Skip to content
Snippets Groups Projects
Commit 3f4cc215 authored by Niels Möller's avatar Niels Möller
Browse files

* macros.h (MD_UPDATE): Added incr argument. Invoke compression

function with ctx pointer as argument, rather than ctx->state.
(MD_FINAL): Just pad, don't store length field. Renamed to MD_PAD.
(MD_PAD): Analogous change of compression invocations.

Rev: nettle/macros.h:1.6
parent fc81fc07
No related branches found
No related tags found
No related merge requests found
...@@ -135,7 +135,6 @@ do { \ ...@@ -135,7 +135,6 @@ do { \
/* Helper macro for Merkle-Damgrd hash functions. Assumes the context /* Helper macro for Merkle-Damgrd hash functions. Assumes the context
structs includes the following fields: structs includes the following fields:
xxx state [...]; // State for the compression function
xxx count_low, count_high; // Two word block count xxx count_low, count_high; // Two word block count
uint8_t block[...]; // Buffer holding one block uint8_t block[...]; // Buffer holding one block
unsigned int index; // Index into block unsigned int index; // Index into block
...@@ -148,7 +147,7 @@ do { \ ...@@ -148,7 +147,7 @@ do { \
/* Takes the compression function f as argument. NOTE: also clobbers /* Takes the compression function f as argument. NOTE: also clobbers
length and data. */ length and data. */
#define MD_UPDATE(ctx, length, data, f) \ #define MD_UPDATE(ctx, length, data, f, incr) \
do { \ do { \
if ((ctx)->index) \ if ((ctx)->index) \
{ \ { \
...@@ -164,17 +163,17 @@ do { \ ...@@ -164,17 +163,17 @@ do { \
{ \ { \
memcpy((ctx)->block + (ctx)->index, (data), __md_left); \ memcpy((ctx)->block + (ctx)->index, (data), __md_left); \
\ \
f((ctx)->state, (ctx)->block); \ f((ctx), (ctx)->block); \
MD_INCR(ctx); \ (incr); \
\ \
(data) += __md_left; \ (data) += __md_left; \
(length) -= __md_left; \ (length) -= __md_left; \
} \ } \
} \ } \
while ((length) >= sizeof((ctx)->block)) \ while ((length) >= sizeof((ctx)->block)) \
{ \ { \
f((ctx)->state, (data)); \ f((ctx), (data)); \
MD_INCR(ctx); \ (incr); \
\ \
(data) += sizeof((ctx)->block); \ (data) += sizeof((ctx)->block); \
(length) -= sizeof((ctx)->block); \ (length) -= sizeof((ctx)->block); \
...@@ -185,13 +184,12 @@ do { \ ...@@ -185,13 +184,12 @@ do { \
; \ ; \
} while (0) } while (0)
/* Final wrapup - pad to block boundary with the bit pattern /* Pads the block to a block boundary with the bit pattern 1 0*,
1 0* (count of bits processed) */ leaving size octets for the length field at the end. If needed,
compresses the block and starts a new one. */
#define MD_FINAL(ctx, bits, shift, f, write) \ #define MD_PAD(ctx, size, f) \
do { \ do { \
unsigned __md_i; \ unsigned __md_i; \
uint##bits##_t __md_low, __md_high; \
__md_i = (ctx)->index; \ __md_i = (ctx)->index; \
\ \
/* Set the first char of padding to 0x80. This is safe since there \ /* Set the first char of padding to 0x80. This is safe since there \
...@@ -205,25 +203,12 @@ do { \ ...@@ -205,25 +203,12 @@ do { \
pad with another one */ \ pad with another one */ \
memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \ memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \
\ \
f((ctx)->state, (ctx)->block); \ f((ctx), (ctx)->block); \
__md_i = 0; \ __md_i = 0; \
} \ } \
memset((ctx)->block + __md_i, 0, \ memset((ctx)->block + __md_i, 0, \
sizeof((ctx)->block) - 2*sizeof((ctx)->count_low) - __md_i); \ sizeof((ctx)->block) - (size) - __md_i); \
\ \
/* There are 2^shift bits in one block */ \
__md_high = ((ctx)->count_high << (shift)) \
| ((ctx)->count_low >> ((bits) - (shift))); \
__md_low = ((ctx)->count_low << (shift)) | ((ctx)->index << 3); \
\
write((ctx)->block \
+ sizeof((ctx)->block) - 2*sizeof((ctx)->count_low), \
__md_high); \
write((ctx)->block \
+ sizeof((ctx)->block) - sizeof((ctx)->count_low), \
__md_low); \
\
f((ctx)->state, (ctx)->block); \
} while (0) } while (0)
#endif /* NETTLE_MACROS_H_INCLUDED */ #endif /* NETTLE_MACROS_H_INCLUDED */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment