Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
4827a371
Commit
4827a371
authored
Sep 14, 2017
by
Sietse Ringers
Browse files
Keyshare wip
parent
bd2de6bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
keyshare.go
View file @
4827a371
...
...
@@ -4,8 +4,6 @@ import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"math/big"
"github.com/mcornejo/go-go-gadget-paillier"
)
...
...
@@ -18,11 +16,10 @@ type keyshareServer struct {
keyGenerator
paillierKeygen
}
// paillierPrivateKey is an alias for paillier.PrivateKey so that we can add a custom unmarshaler to it.
type
paillierPrivateKey
paillier
.
PrivateKey
type
paillierKeygen
interface
{
paillierKey
()
*
paillierPrivateKey
type
keyshareRegistration
struct
{
Username
string
`json:"username"`
Pin
string
`json:"pin"`
PublicKey
paillier
.
PublicKey
`json:"publicKey"`
}
func
newKeyshareServer
(
keygen
paillierKeygen
)
(
ks
*
keyshareServer
,
err
error
)
{
...
...
@@ -44,47 +41,6 @@ func (ks *keyshareServer) GetKey() *paillierPrivateKey {
return
ks
.
PrivateKey
}
func
(
psk
*
paillierPrivateKey
)
UnmarshalJSON
(
bytes
[]
byte
)
(
err
error
)
{
// First try to unmarshal it as a keypair serialized in the old Android format
oldFormat
:=
&
struct
{
PrivateKey
struct
{
L
*
big
.
Int
`json:"lambda"`
U
*
big
.
Int
`json:"preCalculatedDenominator"`
}
`json:"privateKey"`
PublicKey
struct
{
N
*
big
.
Int
`json:"n"`
G
*
big
.
Int
`json:"g"`
NSquared
*
big
.
Int
`json:"nSquared"`
}
`json:"publicKey"`
}{}
if
err
=
json
.
Unmarshal
(
bytes
,
oldFormat
);
err
!=
nil
{
return
}
if
oldFormat
.
PrivateKey
.
L
!=
nil
{
psk
.
L
=
oldFormat
.
PrivateKey
.
L
psk
.
U
=
oldFormat
.
PrivateKey
.
U
psk
.
PublicKey
.
G
=
oldFormat
.
PublicKey
.
G
psk
.
PublicKey
.
N
=
oldFormat
.
PublicKey
.
N
psk
.
PublicKey
.
NSquared
=
oldFormat
.
PublicKey
.
NSquared
return
nil
}
newFormat
:=
new
(
paillier
.
PrivateKey
)
if
err
=
json
.
Unmarshal
(
bytes
,
newFormat
);
err
!=
nil
{
return
}
*
psk
=
paillierPrivateKey
(
*
newFormat
)
return
}
func
(
psk
*
paillierPrivateKey
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
paillier
.
PrivateKey
(
*
psk
))
}
func
(
psk
*
paillierPrivateKey
)
Encrypt
(
bytes
[]
byte
)
([]
byte
,
error
)
{
return
paillier
.
Encrypt
(
&
psk
.
PublicKey
,
bytes
)
}
func
(
psk
*
paillierPrivateKey
)
Decrypt
(
bytes
[]
byte
)
([]
byte
,
error
)
{
return
paillier
.
Decrypt
((
*
paillier
.
PrivateKey
)(
psk
),
bytes
)
func
KeyshareEnroll
(
manager
*
SchemeManager
,
email
,
pin
string
)
error
{
//NewHTTPTransport(qr.URL)
}
manager.go
View file @
4827a371
...
...
@@ -312,3 +312,13 @@ func (cm *CredentialManager) paillierKey() *paillierPrivateKey {
}()
return
retval
}
func
(
cm
*
CredentialManager
)
unenrolledKeyshareServers
()
[]
*
SchemeManager
{
list
:=
[]
*
SchemeManager
{}
for
name
,
manager
:=
range
MetaStore
.
SchemeManagers
{
if
_
,
contains
:=
cm
.
keyshareServers
[
name
];
len
(
manager
.
KeyshareServer
)
>
0
&&
!
contains
{
list
=
append
(
list
,
manager
)
}
}
return
list
}
paillier.go
0 → 100644
View file @
4827a371
package
irmago
import
(
"encoding/json"
"math/big"
paillier
"github.com/mcornejo/go-go-gadget-paillier"
)
// paillierPrivateKey is an alias for paillier.PrivateKey so that we can add a custom unmarshaler to it.
type
paillierPrivateKey
paillier
.
PrivateKey
type
paillierPublicKey
paillier
.
PublicKey
type
paillierKeygen
interface
{
paillierKey
()
*
paillierPrivateKey
}
func
(
psk
*
paillierPrivateKey
)
UnmarshalJSON
(
bytes
[]
byte
)
(
err
error
)
{
// First try to unmarshal it as a keypair serialized in the old Android format
oldFormat
:=
&
struct
{
PrivateKey
struct
{
L
*
big
.
Int
`json:"lambda"`
U
*
big
.
Int
`json:"preCalculatedDenominator"`
}
`json:"privateKey"`
PublicKey
struct
{
N
*
big
.
Int
`json:"n"`
G
*
big
.
Int
`json:"g"`
NSquared
*
big
.
Int
`json:"nSquared"`
}
`json:"publicKey"`
}{}
if
err
=
json
.
Unmarshal
(
bytes
,
oldFormat
);
err
!=
nil
{
return
}
if
oldFormat
.
PrivateKey
.
L
!=
nil
{
psk
.
L
=
oldFormat
.
PrivateKey
.
L
psk
.
U
=
oldFormat
.
PrivateKey
.
U
psk
.
PublicKey
.
G
=
oldFormat
.
PublicKey
.
G
psk
.
PublicKey
.
N
=
oldFormat
.
PublicKey
.
N
psk
.
PublicKey
.
NSquared
=
oldFormat
.
PublicKey
.
NSquared
return
nil
}
newFormat
:=
new
(
paillier
.
PrivateKey
)
if
err
=
json
.
Unmarshal
(
bytes
,
newFormat
);
err
!=
nil
{
return
}
*
psk
=
paillierPrivateKey
(
*
newFormat
)
return
}
func
(
psk
*
paillierPrivateKey
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
paillier
.
PrivateKey
(
*
psk
))
}
func
(
psk
*
paillierPrivateKey
)
Encrypt
(
bytes
[]
byte
)
([]
byte
,
error
)
{
return
paillier
.
Encrypt
(
&
psk
.
PublicKey
,
bytes
)
}
func
(
psk
*
paillierPrivateKey
)
Decrypt
(
bytes
[]
byte
)
([]
byte
,
error
)
{
return
paillier
.
Decrypt
((
*
paillier
.
PrivateKey
)(
psk
),
bytes
)
}
func
(
ppk
*
paillierPublicKey
)
MarshalJSON
()
([]
byte
,
error
)
{
temp
:=
struct
{
N
*
big
.
Int
`json:"n"`
G
*
big
.
Int
`json:"g"`
NSquared
*
big
.
Int
`json:"nSquared"`
Bits
int
`json:"bits"`
}{
ppk
.
N
,
ppk
.
G
,
ppk
.
NSquared
,
ppk
.
N
.
BitLen
()}
return
json
.
Marshal
(
temp
)
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment