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

(byte_swap_32): Deleted macro.

(serpent_key_prepare): Use LE_READ_UINT32. Don't require aligned
input, and support arbitrary key sizes.

Rev: nettle/ChangeLog:1.171
Rev: nettle/serpent.c:1.5
parent 6578740e
2011-05-31 Niels Mller <nisse@lysator.liu.se>
* serpent.c (byte_swap_32): Deleted macro.
(serpent_key_prepare): Use LE_READ_UINT32. Don't require aligned
input, and support arbitrary key sizes.
2011-05-30 Simon Josefsson <simon@josefsson.org> 2011-05-30 Simon Josefsson <simon@josefsson.org>
* serpent.c: Rewrite, based on libgcrypt code. License changed * serpent.c: Rewrite, based on libgcrypt code. License changed
......
...@@ -60,11 +60,6 @@ typedef uint32_t serpent_block_t[4]; ...@@ -60,11 +60,6 @@ typedef uint32_t serpent_block_t[4];
than 256 bits, it is padded. */ than 256 bits, it is padded. */
typedef uint32_t serpent_key_t[8]; typedef uint32_t serpent_key_t[8];
#define byte_swap_32(x) \
(0 \
| (((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \
| (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#define rol(x,n) ((((uint32_t)(x))<<(n))| \ #define rol(x,n) ((((uint32_t)(x))<<(n))| \
(((uint32_t)(x))>>(32-(n)))) (((uint32_t)(x))>>(32-(n))))
#define ror(x,n) ((((uint32_t)(x))<<(32-(n)))| \ #define ror(x,n) ((((uint32_t)(x))<<(32-(n)))| \
...@@ -593,24 +588,25 @@ serpent_key_prepare (const uint8_t * key, unsigned int key_length, ...@@ -593,24 +588,25 @@ serpent_key_prepare (const uint8_t * key, unsigned int key_length,
{ {
unsigned int i; unsigned int i;
assert (key_length <= SERPENT_MAX_KEY_SIZE);
/* Copy key. */ /* Copy key. */
for (i = 0; i < key_length / 4; i++) for (i = 0; key_length >= 4; key_length -=4, key += 4)
{ key_prepared[i++] = LE_READ_UINT32(key);
#ifdef WORDS_BIGENDIAN
key_prepared[i] = byte_swap_32 (((uint32_t *) key)[i]);
#else
key_prepared[i] = ((uint32_t *) key)[i];
#endif
}
if (i < 8) if (i < 8)
{ {
/* Key must be padded according to the Serpent /* Key must be padded according to the Serpent specification.
specification. */ "aabbcc" -> "aabbcc0100...00" -> 0x01ccbbaa. */
key_prepared[i] = 0x00000001; uint32_t pad = 0x01;
while (key_length > 0)
pad = pad << 8 | key[--key_length];
key_prepared[i++] = pad;
for (i++; i < 8; i++) while (i < 8)
key_prepared[i] = 0; key_prepared[i++] = 0;
} }
} }
......
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