Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nettle
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
5
Merge Requests
5
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Nettle
nettle
Commits
36168d29
Commit
36168d29
authored
Feb 19, 2018
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New macros TMP_DECL_ALIGN and TMP_ALLOC_ALIGN.
parent
c5fc9131
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
8 deletions
+41
-8
ChangeLog
ChangeLog
+12
-0
nettle-internal.h
nettle-internal.h
+23
-2
pss-mgf1.c
pss-mgf1.c
+2
-2
pss.c
pss.c
+4
-4
No files found.
ChangeLog
View file @
36168d29
2018-02-19 Niels Möller <nisse@lysator.liu.se>
* nettle-internal.h: Include sha3.h, needed for the definition of
NETTLE_MAX_HASH_CONTEXT_SIZE.
(TMP_DECL_ALIGN, TMP_ALLOC_ALIGN): New macros, to support
allocation of context structs with alignment requirements.
[!HAVE_ALLOCA]: Also use assert, rather than calling abort
directly.
* pss.c (pss_encode_mgf1, pss_verify_mgf1): Use new macros.
* pss-mgf1.c (pss_mgf1): Likewise.
2018-02-18 Niels Möller <nisse@lysator.liu.se>
* testsuite/Makefile.in (TS_NETTLE_SOURCES): Moved pss-mgf1-test.c...
...
...
nettle-internal.h
View file @
36168d29
...
...
@@ -35,20 +35,41 @@
#ifndef NETTLE_INTERNAL_H_INCLUDED
#define NETTLE_INTERNAL_H_INCLUDED
#include <assert.h>
#include "nettle-meta.h"
/* For definition of NETTLE_MAX_HASH_CONTEXT_SIZE. */
#include "sha3.h"
/* Temporary allocation, for systems that don't support alloca. Note
* that the allocation requests should always be reasonably small, so
* that they can fit on the stack. For non-alloca systems, we use a
* fix maximum size, and abort if we ever need anything larger. */
* fix maximum size + an assert.
*
* TMP_DECL and TMP_ALLOC allocate an array of the given type, and
* take the array size (not byte size) as argument.
*
* TMP_DECL_ALIGN and TMP_ALLOC_ALIGN are intended for context
* structs, which need proper alignment. They take the size in bytes,
* and produce a void *. On systems without alloca, implemented as an
* array of uint64_t, to ensure alignment. Since it is used as void *
* argument, no type casts are needed.
*/
#if HAVE_ALLOCA
# define TMP_DECL(name, type, max) type *name
# define TMP_ALLOC(name, size) (name = alloca(sizeof (*name) * (size)))
# define TMP_DECL_ALIGN(name, max) void *name
# define TMP_ALLOC_ALIGN(name, size) (name = alloca(size))
#else
/* !HAVE_ALLOCA */
# define TMP_DECL(name, type, max) type name[max]
# define TMP_ALLOC(name, size) \
do { if ((size) > (sizeof(name) / sizeof(name[0]))) abort(); } while (0)
do { assert((size_t)(size) <= (sizeof(name) / sizeof(name[0]))); } while (0)
# define TMP_DECL_ALIGN(name, max) \
uint64_t name[((max) + (sizeof(uint64_t) - 1))/ sizeof(uint64_t)]
# define TMP_ALLOC_ALIGN(name, size) \
do { assert((size_t)(size) <= (sizeof(name))); } while (0)
#endif
/* Arbitrary limits which apply to systems that don't have alloca */
...
...
pss-mgf1.c
View file @
36168d29
...
...
@@ -48,12 +48,12 @@ pss_mgf1(const void *seed, const struct nettle_hash *hash,
size_t
length
,
uint8_t
*
mask
)
{
TMP_DECL
(
h
,
uint8_t
,
NETTLE_MAX_HASH_DIGEST_SIZE
);
TMP_DECL
(
state
,
uint8_t
,
NETTLE_MAX_HASH_CONTEXT_SIZE
);
TMP_DECL
_ALIGN
(
state
,
NETTLE_MAX_HASH_CONTEXT_SIZE
);
size_t
i
;
uint8_t
c
[
4
];
TMP_ALLOC
(
h
,
hash
->
digest_size
);
TMP_ALLOC
(
state
,
hash
->
context_size
);
TMP_ALLOC
_ALIGN
(
state
,
hash
->
context_size
);
for
(
i
=
0
;;
i
++
,
mask
+=
hash
->
digest_size
,
length
-=
hash
->
digest_size
)
...
...
pss.c
View file @
36168d29
...
...
@@ -67,12 +67,12 @@ pss_encode_mgf1(mpz_t m, size_t bits,
const
uint8_t
*
digest
)
{
TMP_GMP_DECL
(
em
,
uint8_t
);
TMP_DECL
(
state
,
uint8_t
,
NETTLE_MAX_HASH_CONTEXT_SIZE
);
TMP_DECL
_ALIGN
(
state
,
NETTLE_MAX_HASH_CONTEXT_SIZE
);
size_t
key_size
=
(
bits
+
7
)
/
8
;
size_t
j
;
TMP_GMP_ALLOC
(
em
,
key_size
);
TMP_ALLOC
(
state
,
hash
->
context_size
);
TMP_ALLOC
_ALIGN
(
state
,
hash
->
context_size
);
if
(
key_size
<
hash
->
digest_size
+
salt_length
+
2
)
{
...
...
@@ -127,7 +127,7 @@ pss_verify_mgf1(const mpz_t m, size_t bits,
{
TMP_GMP_DECL
(
em
,
uint8_t
);
TMP_DECL
(
h2
,
uint8_t
,
NETTLE_MAX_HASH_DIGEST_SIZE
);
TMP_DECL
(
state
,
uint8_t
,
NETTLE_MAX_HASH_CONTEXT_SIZE
);
TMP_DECL
_ALIGN
(
state
,
NETTLE_MAX_HASH_CONTEXT_SIZE
);
uint8_t
*
h
,
*
db
,
*
salt
;
size_t
key_size
=
(
bits
+
7
)
/
8
;
size_t
j
;
...
...
@@ -138,7 +138,7 @@ pss_verify_mgf1(const mpz_t m, size_t bits,
TMP_GMP_ALLOC
(
em
,
key_size
*
2
);
TMP_ALLOC
(
h2
,
hash
->
digest_size
);
TMP_ALLOC
(
state
,
hash
->
context_size
);
TMP_ALLOC
_ALIGN
(
state
,
hash
->
context_size
);
if
(
key_size
<
hash
->
digest_size
+
salt_length
+
2
)
goto
cleanup
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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