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
a7c217cc
Commit
a7c217cc
authored
11 years ago
by
Donald Stufft
Browse files
Options
Downloads
Patches
Plain Diff
Move the hash functions over to the new layout
parent
8fa69462
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/nacl/_lib/crypto_hash.h
+29
-0
29 additions, 0 deletions
src/nacl/_lib/crypto_hash.h
src/nacl/c/__init__.py
+11
-0
11 additions, 0 deletions
src/nacl/c/__init__.py
src/nacl/c/crypto_hash.py
+62
-0
62 additions, 0 deletions
src/nacl/c/crypto_hash.py
src/nacl/hash.py
+6
-17
6 additions, 17 deletions
src/nacl/hash.py
with
108 additions
and
17 deletions
src/nacl/_lib/crypto_hash.h
0 → 100644
+
29
−
0
View file @
a7c217cc
/* Copyright 2013 Donald Stufft and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// size_t crypto_hash_bytes();
size_t
crypto_hash_sha256_bytes
();
size_t
crypto_hash_sha512_bytes
();
int
crypto_hash
(
unsigned
char
*
out
,
const
unsigned
char
*
in
,
unsigned
long
long
inlen
);
int
crypto_hash_sha256
(
unsigned
char
*
out
,
const
unsigned
char
*
in
,
unsigned
long
long
inlen
);
int
crypto_hash_sha512
(
unsigned
char
*
out
,
const
unsigned
char
*
in
,
unsigned
long
long
inlen
);
This diff is collapsed.
Click to expand it.
src/nacl/c/__init__.py
+
11
−
0
View file @
a7c217cc
...
@@ -19,6 +19,10 @@ from nacl.c.crypto_box import (
...
@@ -19,6 +19,10 @@ from nacl.c.crypto_box import (
crypto_box_BEFORENMBYTES
,
crypto_box_keypair
,
crypto_box
,
crypto_box_open
,
crypto_box_BEFORENMBYTES
,
crypto_box_keypair
,
crypto_box
,
crypto_box_open
,
crypto_box_beforenm
,
crypto_box_afternm
,
crypto_box_open_afternm
,
crypto_box_beforenm
,
crypto_box_afternm
,
crypto_box_open_afternm
,
)
)
from
nacl.c.crypto_hash
import
(
crypto_hash_BYTES
,
crypto_hash_sha256_BYTES
,
crypto_hash_sha512_BYTES
,
crypto_hash
,
crypto_hash_sha256
,
crypto_hash_sha512
,
)
from
nacl.c.crypto_scalarmult
import
(
from
nacl.c.crypto_scalarmult
import
(
crypto_scalarmult_BYTES
,
crypto_scalarmult_SCALARBYTES
,
crypto_scalarmult_BYTES
,
crypto_scalarmult_SCALARBYTES
,
crypto_scalarmult_base
,
crypto_scalarmult_base
,
...
@@ -50,6 +54,13 @@ __all__ = [
...
@@ -50,6 +54,13 @@ __all__ = [
"
crypto_box_afternm
"
,
"
crypto_box_afternm
"
,
"
crypto_box_open_afternm
"
,
"
crypto_box_open_afternm
"
,
"
crypto_hash_BYTES
"
,
"
crypto_hash_sha256_BYTES
"
,
"
crypto_hash_sha512_BYTES
"
,
"
crypto_hash
"
,
"
crypto_hash_sha256
"
,
"
crypto_hash_sha512
"
,
"
crypto_scalarmult_BYTES
"
,
"
crypto_scalarmult_BYTES
"
,
"
crypto_scalarmult_SCALARBYTES
"
,
"
crypto_scalarmult_SCALARBYTES
"
,
"
crypto_scalarmult_base
"
,
"
crypto_scalarmult_base
"
,
...
...
This diff is collapsed.
Click to expand it.
src/nacl/c/crypto_hash.py
0 → 100644
+
62
−
0
View file @
a7c217cc
# Copyright 2013 Donald Stufft and individual contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
from
nacl
import
_lib
as
lib
from
nacl.exceptions
import
CryptoError
# crypto_hash_BYTES = lib.crypto_hash_bytes()
crypto_hash_BYTES
=
lib
.
crypto_hash_sha512_bytes
()
crypto_hash_sha256_BYTES
=
lib
.
crypto_hash_sha256_bytes
()
crypto_hash_sha512_BYTES
=
lib
.
crypto_hash_sha512_bytes
()
def
crypto_hash
(
message
):
"""
Hashes and returns the message ``message``.
:param message: bytes
:rtype: bytes
"""
digest
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_hash_BYTES
)
if
lib
.
crypto_hash
(
digest
,
message
,
len
(
message
))
!=
0
:
raise
CryptoError
(
"
Hashing failed
"
)
return
lib
.
ffi
.
buffer
(
digest
,
crypto_hash_BYTES
)[:]
def
crypto_hash_sha256
(
message
):
"""
Hashes and returns the message ``message``.
:param message: bytes
:rtype: bytes
"""
digest
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_hash_sha256_BYTES
)
if
lib
.
crypto_hash_sha256
(
digest
,
message
,
len
(
message
))
!=
0
:
raise
CryptoError
(
"
Hashing failed
"
)
return
lib
.
ffi
.
buffer
(
digest
,
crypto_hash_sha256_BYTES
)[:]
def
crypto_hash_sha512
(
message
):
"""
Hashes and returns the message ``message``.
:param message: bytes
:rtype: bytes
"""
digest
=
lib
.
ffi
.
new
(
"
unsigned char[]
"
,
crypto_hash_sha512_BYTES
)
if
lib
.
crypto_hash_sha512
(
digest
,
message
,
len
(
message
))
!=
0
:
raise
CryptoError
(
"
Hashing failed
"
)
return
lib
.
ffi
.
buffer
(
digest
,
crypto_hash_sha512_BYTES
)[:]
This diff is collapsed.
Click to expand it.
src/nacl/hash.py
+
6
−
17
View file @
a7c217cc
...
@@ -14,24 +14,13 @@
...
@@ -14,24 +14,13 @@
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
division
from
.
import
encoding
import
nacl.c
from
.c
import
_lib
as
nacl
import
nacl.encoding
from
.exceptions
import
CryptoError
def
sha256
(
message
,
encoder
=
encoding
.
HexEncoder
):
def
sha256
(
message
,
encoder
=
nacl
.
encoding
.
HexEncoder
):
digest
=
nacl
.
ffi
.
new
(
"
unsigned char[]
"
,
nacl
.
lib
.
crypto_hash_sha256_BYTES
)
return
encoder
.
encode
(
nacl
.
c
.
crypto_hash_sha256
(
message
))
if
not
nacl
.
lib
.
crypto_hash_sha256
(
digest
,
message
,
len
(
message
)):
raise
CryptoError
(
"
Hashing failed
"
)
digest
=
nacl
.
ffi
.
buffer
(
digest
,
nacl
.
lib
.
crypto_hash_sha256_BYTES
)[:]
return
encoder
.
encode
(
digest
)
def
sha512
(
message
,
encoder
=
nacl
.
encoding
.
HexEncoder
):
def
sha512
(
message
,
encoder
=
encoding
.
HexEncoder
):
return
encoder
.
encode
(
nacl
.
c
.
crypto_hash_sha512
(
message
))
digest
=
nacl
.
ffi
.
new
(
"
unsigned char[]
"
,
nacl
.
lib
.
crypto_hash_sha512_BYTES
)
if
not
nacl
.
lib
.
crypto_hash_sha512
(
digest
,
message
,
len
(
message
)):
raise
CryptoError
(
"
Hashing failed
"
)
digest
=
nacl
.
ffi
.
buffer
(
digest
,
nacl
.
lib
.
crypto_hash_sha512_BYTES
)[:]
return
encoder
.
encode
(
digest
)
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