Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
b81177c0
Commit
b81177c0
authored
10 years ago
by
Brian Warner
Browse files
Options
Downloads
Patches
Plain Diff
fix raw crypto_sign API
parent
e0fc13b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/nacl/c/crypto_sign.py
+12
-12
12 additions, 12 deletions
src/nacl/c/crypto_sign.py
src/nacl/signing.py
+3
-3
3 additions, 3 deletions
src/nacl/signing.py
tests/test_raw.py
+4
-7
4 additions, 7 deletions
tests/test_raw.py
with
19 additions
and
22 deletions
src/nacl/c/crypto_sign.py
+
12
−
12
View file @
b81177c0
...
...
@@ -26,51 +26,51 @@ crypto_sign_SECRETKEYBYTES = lib.crypto_sign_secretkeybytes()
def
crypto_sign_keypair
():
"""
Returns a randomly generated
secret
key and
public
key.
Returns a randomly generated
public
key and
secret
key.
:rtype: (bytes(
secret
_key), bytes(
public
_key))
:rtype: (bytes(
public
_key), bytes(
secret
_key))
"""
sk
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_sign_SECRETKEYBYTES
)
pk
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_sign_PUBLICKEYBYTES
)
sk
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_sign_SECRETKEYBYTES
)
if
lib
.
crypto_sign_keypair
(
pk
,
sk
)
!=
0
:
raise
CryptoError
(
"
An error occurred while generating keypairs
"
)
return
(
lib
.
ffi
.
buffer
(
sk
,
crypto_sign_SECRETKEYBYTES
)[:],
lib
.
ffi
.
buffer
(
pk
,
crypto_sign_PUBLICKEYBYTES
)[:],
lib
.
ffi
.
buffer
(
sk
,
crypto_sign_SECRETKEYBYTES
)[:],
)
def
crypto_sign_seed_keypair
(
seed
):
"""
Computes and returns the
secret
key and
public
key using the seed ``seed``.
Computes and returns the
public
key and
secret
key using the seed ``seed``.
:param seed: bytes
:rtype: (bytes(
secret
_key), bytes(
public
_key))
:rtype: (bytes(
public
_key), bytes(
secret
_key))
"""
if
len
(
seed
)
!=
crypto_sign_SEEDBYTES
:
raise
ValueError
(
"
Invalid seed
"
)
sk
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_sign_SECRETKEYBYTES
)
pk
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_sign_PUBLICKEYBYTES
)
sk
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_sign_SECRETKEYBYTES
)
if
lib
.
crypto_sign_seed_keypair
(
pk
,
sk
,
seed
)
!=
0
:
raise
CryptoError
(
"
An error occured while generating keypairs
"
)
return
(
lib
.
ffi
.
buffer
(
sk
,
crypto_sign_SECRETKEYBYTES
)[:],
lib
.
ffi
.
buffer
(
pk
,
crypto_sign_PUBLICKEYBYTES
)[:],
lib
.
ffi
.
buffer
(
sk
,
crypto_sign_SECRETKEYBYTES
)[:],
)
def
crypto_sign
(
sk
,
message
):
def
crypto_sign
(
message
,
sk
):
"""
Signs the message ``message`` using the secret key ``sk`` and returns the
signed message.
:param sk: bytes
:param message: bytes
:param sk: bytes
:rtype: bytes
"""
signed
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
len
(
message
)
+
crypto_sign_BYTES
)
...
...
@@ -82,13 +82,13 @@ def crypto_sign(sk, message):
return
lib
.
ffi
.
buffer
(
signed
,
signed_len
[
0
])[:]
def
crypto_sign_open
(
pk
,
signed
):
def
crypto_sign_open
(
signed
,
pk
):
"""
Verifies the signature of the signed message ``signed`` using the public
key ``pkg`` and returns the unsigned message.
:param pk: bytes
:param signed: bytes
:param pk: bytes
:rtype: bytes
"""
message
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
len
(
signed
))
...
...
This diff is collapsed.
Click to expand it.
src/nacl/signing.py
+
3
−
3
View file @
b81177c0
...
...
@@ -96,7 +96,7 @@ class VerifyKey(encoding.Encodable, StringFixer, object):
# Decode the signed message
smessage
=
encoder
.
decode
(
smessage
)
return
nacl
.
c
.
crypto_sign_open
(
s
elf
.
_key
,
smessage
)
return
nacl
.
c
.
crypto_sign_open
(
s
message
,
self
.
_key
)
class
SigningKey
(
encoding
.
Encodable
,
StringFixer
,
object
):
...
...
@@ -129,7 +129,7 @@ class SigningKey(encoding.Encodable, StringFixer, object):
nacl
.
c
.
crypto_sign_SEEDBYTES
)
secret_key
,
public
_key
=
nacl
.
c
.
crypto_sign_seed_keypair
(
seed
)
public_key
,
secret
_key
=
nacl
.
c
.
crypto_sign_seed_keypair
(
seed
)
self
.
_seed
=
seed
self
.
_signing_key
=
secret_key
...
...
@@ -158,7 +158,7 @@ class SigningKey(encoding.Encodable, StringFixer, object):
:param encoder: A class that is used to encode the signed message.
:rtype: :class:`~nacl.signing.SignedMessage`
"""
raw_signed
=
nacl
.
c
.
crypto_sign
(
self
.
_signing_key
,
message
)
raw_signed
=
nacl
.
c
.
crypto_sign
(
message
,
self
.
_signing_key
)
signature
=
encoder
.
encode
(
raw_signed
[:
nacl
.
c
.
crypto_sign_BYTES
])
message
=
encoder
.
encode
(
raw_signed
[
nacl
.
c
.
crypto_sign_BYTES
:])
...
...
This diff is collapsed.
Click to expand it.
tests/test_raw.py
+
4
−
7
View file @
b81177c0
...
...
@@ -70,23 +70,20 @@ def test_box():
def
test_sign
():
# TODO: NaCl C++ is pk=keypair(sk), C is keypair(pk,sk)
seed
=
"
\x00
"
*
c
.
crypto_sign_SEEDBYTES
secretkey
,
pub
key
=
c
.
crypto_sign_seed_keypair
(
seed
)
pubkey
,
secret
key
=
c
.
crypto_sign_seed_keypair
(
seed
)
assert
len
(
pubkey
)
==
c
.
crypto_sign_PUBLICKEYBYTES
assert
len
(
secretkey
)
==
c
.
crypto_sign_SECRETKEYBYTES
secretkey
,
pub
key
=
c
.
crypto_sign_keypair
()
pubkey
,
secret
key
=
c
.
crypto_sign_keypair
()
assert
len
(
pubkey
)
==
c
.
crypto_sign_PUBLICKEYBYTES
assert
len
(
secretkey
)
==
c
.
crypto_sign_SECRETKEYBYTES
# TODO: NaCl is sm=sign(msg, sk)
msg
=
"
message
"
sigmsg
=
c
.
crypto_sign
(
secretkey
,
msg
)
sigmsg
=
c
.
crypto_sign
(
msg
,
secretkey
)
assert
len
(
sigmsg
)
==
len
(
msg
)
+
c
.
crypto_sign_BYTES
# TODO: NaCl is msg=open(sm, pk)
msg2
=
c
.
crypto_sign_open
(
pubkey
,
sigmsg
)
msg2
=
c
.
crypto_sign_open
(
sigmsg
,
pubkey
)
assert
msg2
==
msg
def
secret_scalar
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment