Commit fab55772 authored by Niels Möller's avatar Niels Möller
Browse files

* macros.h (INCREMENT): New macro, moved from ctr.c. Deleted third

argument.
* ctr.c: Use INCREMENT macro from macros.h, deleted local version.

Rev: nettle/ChangeLog:1.128
Rev: nettle/ctr.c:1.2
Rev: nettle/macros.h:1.3
parent 9ac77d39
2011-02-05 Niels Mller <nisse@lysator.liu.se>
* macros.h (INCREMENT): New macro, moved from ctr.c. Deleted third
argument.
* ctr.c: Use INCREMENT macro from macros.h, deleted local version.
2011-01-07 Niels Mller <nisse@lysator.liu.se> 2011-01-07 Niels Mller <nisse@lysator.liu.se>
* testsuite/Makefile.in (check): Add ../.lib to PATH, since that's * testsuite/Makefile.in (check): Add ../.lib to PATH, since that's
......
...@@ -33,19 +33,10 @@ ...@@ -33,19 +33,10 @@
#include "ctr.h" #include "ctr.h"
#include "macros.h"
#include "memxor.h" #include "memxor.h"
#include "nettle-internal.h" #include "nettle-internal.h"
#define INCREMENT(size, counter, i) \
do { \
if (++(ctr)[(size) - 1] == 0) \
{ \
unsigned i = size - 1; \
while (i > 0 && ++(ctr)[--i] == 0) \
; \
} \
} while (0)
void void
ctr_crypt(void *ctx, nettle_crypt_func f, ctr_crypt(void *ctx, nettle_crypt_func f,
unsigned block_size, uint8_t *ctr, unsigned block_size, uint8_t *ctr,
...@@ -61,7 +52,7 @@ ctr_crypt(void *ctx, nettle_crypt_func f, ...@@ -61,7 +52,7 @@ ctr_crypt(void *ctx, nettle_crypt_func f,
{ {
f(ctx, block_size, dst, ctr); f(ctx, block_size, dst, ctr);
memxor(dst, src, block_size); memxor(dst, src, block_size);
INCREMENT(block_size, ctr, i); INCREMENT(block_size, ctr);
} }
} }
else else
...@@ -70,7 +61,7 @@ ctr_crypt(void *ctx, nettle_crypt_func f, ...@@ -70,7 +61,7 @@ ctr_crypt(void *ctx, nettle_crypt_func f,
{ {
f(ctx, block_size, buffer, ctr); f(ctx, block_size, buffer, ctr);
memxor3(dst, src, buffer, block_size); memxor3(dst, src, buffer, block_size);
INCREMENT(block_size, ctr, i); INCREMENT(block_size, ctr);
} }
} }
if (length > 0) if (length > 0)
...@@ -79,6 +70,6 @@ ctr_crypt(void *ctx, nettle_crypt_func f, ...@@ -79,6 +70,6 @@ ctr_crypt(void *ctx, nettle_crypt_func f,
f(ctx, block_size, buffer, ctr); f(ctx, block_size, buffer, ctr);
memxor3(dst, src, buffer, length); memxor3(dst, src, buffer, length);
INCREMENT(block_size, ctr, i); INCREMENT(block_size, ctr);
} }
} }
...@@ -119,4 +119,16 @@ do { \ ...@@ -119,4 +119,16 @@ do { \
(dst) += (blocksize), \ (dst) += (blocksize), \
(src) += (blocksize)) ) (src) += (blocksize)) )
/* Requires that size >= 2 */
#define INCREMENT(size, ctr) \
do { \
unsigned increment_i = (size) - 1; \
if (++(ctr)[increment_i] == 0) \
{ \
while (++(ctr)[--increment_i] == 0 \
&& increment_i > 0) \
; \
} \
} while (0)
#endif /* NETTLE_MACROS_H_INCLUDED */ #endif /* NETTLE_MACROS_H_INCLUDED */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment