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
GitLab 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
660a7ba6
Commit
660a7ba6
authored
11 years ago
by
Brian Warner
Browse files
Options
Downloads
Patches
Plain Diff
fix raw crypto_secretbox API
parent
7ab615aa
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/nacl/c/crypto_secretbox.py
+4
-4
4 additions, 4 deletions
src/nacl/c/crypto_secretbox.py
src/nacl/secret.py
+2
-2
2 additions, 2 deletions
src/nacl/secret.py
tests/test_raw.py
+2
-4
2 additions, 4 deletions
tests/test_raw.py
with
8 additions
and
10 deletions
src/nacl/c/crypto_secretbox.py
+
4
−
4
View file @
660a7ba6
...
@@ -23,14 +23,14 @@ crypto_secretbox_ZEROBYTES = lib.crypto_secretbox_zerobytes()
...
@@ -23,14 +23,14 @@ crypto_secretbox_ZEROBYTES = lib.crypto_secretbox_zerobytes()
crypto_secretbox_BOXZEROBYTES
=
lib
.
crypto_secretbox_boxzerobytes
()
crypto_secretbox_BOXZEROBYTES
=
lib
.
crypto_secretbox_boxzerobytes
()
def
crypto_secretbox
(
key
,
message
,
nonce
):
def
crypto_secretbox
(
message
,
nonce
,
key
):
"""
"""
Encrypts and returns the message ``message`` with the secret ``key`` and
Encrypts and returns the message ``message`` with the secret ``key`` and
the nonce ``nonce``.
the nonce ``nonce``.
:param key: bytes
:param message: bytes
:param message: bytes
:param nonce: bytes
:param nonce: bytes
:param key: bytes
:rtype: bytes
:rtype: bytes
"""
"""
if
len
(
key
)
!=
crypto_secretbox_KEYBYTES
:
if
len
(
key
)
!=
crypto_secretbox_KEYBYTES
:
...
@@ -49,14 +49,14 @@ def crypto_secretbox(key, message, nonce):
...
@@ -49,14 +49,14 @@ def crypto_secretbox(key, message, nonce):
return
ciphertext
[
crypto_secretbox_BOXZEROBYTES
:]
return
ciphertext
[
crypto_secretbox_BOXZEROBYTES
:]
def
crypto_secretbox_open
(
key
,
ciphertext
,
nonce
):
def
crypto_secretbox_open
(
ciphertext
,
nonce
,
key
):
"""
"""
Decrypt and returns the encrypted message ``ciphertext`` with the secret
Decrypt and returns the encrypted message ``ciphertext`` with the secret
``key`` and the nonce ``nonce``.
``key`` and the nonce ``nonce``.
:param key: bytes
:param ciphertext: bytes
:param ciphertext: bytes
:param nonce: bytes
:param nonce: bytes
:param key: bytes
:rtype: bytes
:rtype: bytes
"""
"""
if
len
(
key
)
!=
crypto_secretbox_KEYBYTES
:
if
len
(
key
)
!=
crypto_secretbox_KEYBYTES
:
...
...
This diff is collapsed.
Click to expand it.
src/nacl/secret.py
+
2
−
2
View file @
660a7ba6
...
@@ -78,7 +78,7 @@ class SecretBox(encoding.Encodable, StringFixer, object):
...
@@ -78,7 +78,7 @@ class SecretBox(encoding.Encodable, StringFixer, object):
"
The nonce must be exactly %s bytes long
"
%
self
.
NONCE_SIZE
,
"
The nonce must be exactly %s bytes long
"
%
self
.
NONCE_SIZE
,
)
)
ciphertext
=
nacl
.
c
.
crypto_secretbox
(
self
.
_key
,
plaintext
,
nonce
)
ciphertext
=
nacl
.
c
.
crypto_secretbox
(
plaintext
,
nonce
,
self
.
_key
)
encoded_nonce
=
encoder
.
encode
(
nonce
)
encoded_nonce
=
encoder
.
encode
(
nonce
)
encoded_ciphertext
=
encoder
.
encode
(
ciphertext
)
encoded_ciphertext
=
encoder
.
encode
(
ciphertext
)
...
@@ -113,6 +113,6 @@ class SecretBox(encoding.Encodable, StringFixer, object):
...
@@ -113,6 +113,6 @@ class SecretBox(encoding.Encodable, StringFixer, object):
"
The nonce must be exactly %s bytes long
"
%
self
.
NONCE_SIZE
,
"
The nonce must be exactly %s bytes long
"
%
self
.
NONCE_SIZE
,
)
)
plaintext
=
nacl
.
c
.
crypto_secretbox_open
(
self
.
_key
,
ciphertext
,
nonce
)
plaintext
=
nacl
.
c
.
crypto_secretbox_open
(
ciphertext
,
nonce
,
self
.
_key
)
return
plaintext
return
plaintext
This diff is collapsed.
Click to expand it.
tests/test_raw.py
+
2
−
4
View file @
660a7ba6
...
@@ -37,12 +37,10 @@ def test_secretbox():
...
@@ -37,12 +37,10 @@ def test_secretbox():
key
=
"
\x00
"
*
c
.
crypto_secretbox_KEYBYTES
key
=
"
\x00
"
*
c
.
crypto_secretbox_KEYBYTES
msg
=
"
message
"
msg
=
"
message
"
nonce
=
"
\x01
"
*
c
.
crypto_secretbox_NONCEBYTES
nonce
=
"
\x01
"
*
c
.
crypto_secretbox_NONCEBYTES
# TODO: NaCl is secretbox(msg,nonce,key)
ct
=
c
.
crypto_secretbox
(
msg
,
nonce
,
key
)
ct
=
c
.
crypto_secretbox
(
key
,
msg
,
nonce
)
assert
len
(
ct
)
==
len
(
msg
)
+
c
.
crypto_secretbox_BOXZEROBYTES
assert
len
(
ct
)
==
len
(
msg
)
+
c
.
crypto_secretbox_BOXZEROBYTES
assert
hexlify
(
ct
)
==
"
3ae84dfb89728737bd6e2c8cacbaf8af3d34cc1666533a
"
assert
hexlify
(
ct
)
==
"
3ae84dfb89728737bd6e2c8cacbaf8af3d34cc1666533a
"
# TODO: NaCl is secretbox_open(ct,nonce,key)
msg2
=
c
.
crypto_secretbox_open
(
ct
,
nonce
,
key
)
msg2
=
c
.
crypto_secretbox_open
(
key
,
ct
,
nonce
)
assert
msg2
==
msg
assert
msg2
==
msg
def
test_box
():
def
test_box
():
...
...
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