summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Esser <besser82@fedoraproject.org>2017-10-23 10:36:38 +0200
committerBjörn Esser <besser82@fedoraproject.org>2017-10-23 10:39:53 +0200
commit55216e31ab2e2355b87beea2cb9f0ed93cdc28cd (patch)
tree809ea769d7d57ad510f6dd3ba1dd662233d43843
parenta0be271d98551c77a1465cfec088fe645ebecec9 (diff)
downloadlibxcrypt-55216e31ab2e2355b87beea2cb9f0ed93cdc28cd.tar.gz
libxcrypt-55216e31ab2e2355b87beea2cb9f0ed93cdc28cd.tar.bz2
libxcrypt-55216e31ab2e2355b87beea2cb9f0ed93cdc28cd.zip
Reformat all code files to match GNU style
-rw-r--r--.gitignore4
-rw-r--r--alg-des.c89
-rw-r--r--alg-md4.c199
-rw-r--r--alg-sha256.c5
-rw-r--r--alg-sha512.c3
-rw-r--r--crypt-base.h14
-rw-r--r--crypt-bcrypt.c147
-rw-r--r--crypt-des.c6
-rw-r--r--crypt-md5.c2
-rw-r--r--crypt-nthash.c45
-rw-r--r--crypt-obsolete.h8
-rw-r--r--crypt.c17
-rw-r--r--gen-des-tables.c394
-rw-r--r--test-alg-des.c4
-rw-r--r--test-alg-md4.c48
-rw-r--r--test-alg-md5.c60
-rw-r--r--test-alg-sha256.c76
-rw-r--r--test-alg-sha512.c122
-rw-r--r--test-byteorder.c12
-rw-r--r--test-crypt-badsalt.c58
-rw-r--r--test-crypt-bcrypt.c171
-rw-r--r--test-crypt-des.c18
-rw-r--r--test-crypt-nonnull.c44
-rw-r--r--test-crypt-nthash.c144
-rw-r--r--test-crypt-sha256.c42
-rw-r--r--test-crypt-sha512.c42
-rw-r--r--test-des-cases.h3
-rw-r--r--test-des-obsolete.c4
-rw-r--r--test-des-obsolete_r.c4
-rw-r--r--test-gensalt.c6
30 files changed, 1021 insertions, 770 deletions
diff --git a/.gitignore b/.gitignore
index c35b42f..5105cd6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -76,3 +76,7 @@
# Valgrind
vgcore.*
+
+# Patch
+*.orig
+*.rej
diff --git a/alg-des.c b/alg-des.c
index ca5d760..3e62fe2 100644
--- a/alg-des.c
+++ b/alg-des.c
@@ -62,7 +62,8 @@
#include "alg-des.h"
#include "byteorder.h"
-static const uint8_t key_shifts[16] = {
+static const uint8_t key_shifts[16] =
+{
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
};
@@ -77,21 +78,21 @@ des_set_key (struct des_ctx *restrict ctx, const unsigned char *key)
/* Do key permutation and split into two 28-bit subkeys. */
k0 = key_perm_maskl[0][rawkey0 >> 25]
- | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
- | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
- | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
- | key_perm_maskl[4][rawkey1 >> 25]
- | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
- | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
- | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
+ | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskl[4][rawkey1 >> 25]
+ | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
k1 = key_perm_maskr[0][rawkey0 >> 25]
- | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
- | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
- | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
- | key_perm_maskr[4][rawkey1 >> 25]
- | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
- | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
- | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
+ | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskr[4][rawkey1 >> 25]
+ | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
/* Rotate subkeys and do compression permutation. */
shifts = 0;
@@ -103,7 +104,7 @@ des_set_key (struct des_ctx *restrict ctx, const unsigned char *key)
t1 = (k1 << shifts) | (k1 >> (28 - shifts));
ctx->keysl[round] =
- comp_maskl[0][(t0 >> 21) & 0x7f]
+ comp_maskl[0][(t0 >> 21) & 0x7f]
| comp_maskl[1][(t0 >> 14) & 0x7f]
| comp_maskl[2][(t0 >> 7) & 0x7f]
| comp_maskl[3][(t0 >> 0) & 0x7f]
@@ -113,7 +114,7 @@ des_set_key (struct des_ctx *restrict ctx, const unsigned char *key)
| comp_maskl[7][(t1 >> 0) & 0x7f];
ctx->keysr[round] =
- comp_maskr[0][(t0 >> 21) & 0x7f]
+ comp_maskr[0][(t0 >> 21) & 0x7f]
| comp_maskr[1][(t0 >> 14) & 0x7f]
| comp_maskr[2][(t0 >> 7) & 0x7f]
| comp_maskr[3][(t0 >> 0) & 0x7f]
@@ -176,21 +177,21 @@ des_crypt_block (struct des_ctx *restrict ctx,
/* Do initial permutation. */
l = ip_maskl[0][(l_in >> 24) & 0xff]
- | ip_maskl[1][(l_in >> 16) & 0xff]
- | ip_maskl[2][(l_in >> 8) & 0xff]
- | ip_maskl[3][(l_in >> 0) & 0xff]
- | ip_maskl[4][(r_in >> 24) & 0xff]
- | ip_maskl[5][(r_in >> 16) & 0xff]
- | ip_maskl[6][(r_in >> 8) & 0xff]
- | ip_maskl[7][(r_in >> 0) & 0xff];
+ | ip_maskl[1][(l_in >> 16) & 0xff]
+ | ip_maskl[2][(l_in >> 8) & 0xff]
+ | ip_maskl[3][(l_in >> 0) & 0xff]
+ | ip_maskl[4][(r_in >> 24) & 0xff]
+ | ip_maskl[5][(r_in >> 16) & 0xff]
+ | ip_maskl[6][(r_in >> 8) & 0xff]
+ | ip_maskl[7][(r_in >> 0) & 0xff];
r = ip_maskr[0][(l_in >> 24) & 0xff]
- | ip_maskr[1][(l_in >> 16) & 0xff]
- | ip_maskr[2][(l_in >> 8) & 0xff]
- | ip_maskr[3][(l_in >> 0) & 0xff]
- | ip_maskr[4][(r_in >> 24) & 0xff]
- | ip_maskr[5][(r_in >> 16) & 0xff]
- | ip_maskr[6][(r_in >> 8) & 0xff]
- | ip_maskr[7][(r_in >> 0) & 0xff];
+ | ip_maskr[1][(l_in >> 16) & 0xff]
+ | ip_maskr[2][(l_in >> 8) & 0xff]
+ | ip_maskr[3][(l_in >> 0) & 0xff]
+ | ip_maskr[4][(r_in >> 24) & 0xff]
+ | ip_maskr[5][(r_in >> 16) & 0xff]
+ | ip_maskr[6][(r_in >> 8) & 0xff]
+ | ip_maskr[7][(r_in >> 0) & 0xff];
do
{
@@ -201,15 +202,15 @@ des_crypt_block (struct des_ctx *restrict ctx,
{
/* Expand R to 48 bits (simulate the E-box). */
r48l = ((r & 0x00000001) << 23)
- | ((r & 0xf8000000) >> 9)
- | ((r & 0x1f800000) >> 11)
- | ((r & 0x01f80000) >> 13)
- | ((r & 0x001f8000) >> 15);
+ | ((r & 0xf8000000) >> 9)
+ | ((r & 0x1f800000) >> 11)
+ | ((r & 0x01f80000) >> 13)
+ | ((r & 0x001f8000) >> 15);
r48r = ((r & 0x0001f800) << 7)
- | ((r & 0x00001f80) << 5)
- | ((r & 0x000001f8) << 3)
- | ((r & 0x0000001f) << 1)
- | ((r & 0x80000000) >> 31);
+ | ((r & 0x00001f80) << 5)
+ | ((r & 0x000001f8) << 3)
+ | ((r & 0x0000001f) << 1)
+ | ((r & 0x80000000) >> 31);
/* Apply salt and permuted round key. */
f = (r48l ^ r48r) & saltbits;
@@ -221,9 +222,9 @@ des_crypt_block (struct des_ctx *restrict ctx,
/* Do sbox lookups (which shrink it back to 32 bits)
and the pbox permutation at the same time. */
f = psbox[0][m_sbox[0][r48l >> 12]]
- | psbox[1][m_sbox[1][r48l & 0xfff]]
- | psbox[2][m_sbox[2][r48r >> 12]]
- | psbox[3][m_sbox[3][r48r & 0xfff]];
+ | psbox[1][m_sbox[1][r48l & 0xfff]]
+ | psbox[2][m_sbox[2][r48r >> 12]]
+ | psbox[3][m_sbox[3][r48r & 0xfff]];
/* Now that we've permuted things, complete f(). */
f ^= l;
@@ -239,7 +240,7 @@ des_crypt_block (struct des_ctx *restrict ctx,
/* Do final permutation (inverse of IP). */
l_out =
- fp_maskl[0][(l >> 24) & 0xff]
+ fp_maskl[0][(l >> 24) & 0xff]
| fp_maskl[1][(l >> 16) & 0xff]
| fp_maskl[2][(l >> 8) & 0xff]
| fp_maskl[3][(l >> 0) & 0xff]
@@ -248,7 +249,7 @@ des_crypt_block (struct des_ctx *restrict ctx,
| fp_maskl[6][(r >> 8) & 0xff]
| fp_maskl[7][(r >> 0) & 0xff];
r_out =
- fp_maskr[0][(l >> 24) & 0xff]
+ fp_maskr[0][(l >> 24) & 0xff]
| fp_maskr[1][(l >> 16) & 0xff]
| fp_maskr[2][(l >> 8) & 0xff]
| fp_maskr[3][(l >> 0) & 0xff]
diff --git a/alg-md4.c b/alg-md4.c
index 84c9308..4c1fa46 100644
--- a/alg-md4.c
+++ b/alg-md4.c
@@ -67,82 +67,83 @@ body (struct md4_ctx *ctx, const unsigned char *data, size_t size)
d = ctx->d;
do
- {
- saved_a = a;
- saved_b = b;
- saved_c = c;
- saved_d = d;
-
- /* Round 1 */
- STEP(F, a, b, c, d, SET( 0), 3);
- STEP(F, d, a, b, c, SET( 1), 7);
- STEP(F, c, d, a, b, SET( 2), 11);
- STEP(F, b, c, d, a, SET( 3), 19);
-
- STEP(F, a, b, c, d, SET( 4), 3);
- STEP(F, d, a, b, c, SET( 5), 7);
- STEP(F, c, d, a, b, SET( 6), 11);
- STEP(F, b, c, d, a, SET( 7), 19);
-
- STEP(F, a, b, c, d, SET( 8), 3);
- STEP(F, d, a, b, c, SET( 9), 7);
- STEP(F, c, d, a, b, SET(10), 11);
- STEP(F, b, c, d, a, SET(11), 19);
-
- STEP(F, a, b, c, d, SET(12), 3);
- STEP(F, d, a, b, c, SET(13), 7);
- STEP(F, c, d, a, b, SET(14), 11);
- STEP(F, b, c, d, a, SET(15), 19);
-
- /* Round 2 */
- STEP(G, a, b, c, d, GET( 0) + 0x5A827999, 3);
- STEP(G, d, a, b, c, GET( 4) + 0x5A827999, 5);
- STEP(G, c, d, a, b, GET( 8) + 0x5A827999, 9);
- STEP(G, b, c, d, a, GET(12) + 0x5A827999, 13);
-
- STEP(G, a, b, c, d, GET( 1) + 0x5A827999, 3);
- STEP(G, d, a, b, c, GET( 5) + 0x5A827999, 5);
- STEP(G, c, d, a, b, GET( 9) + 0x5A827999, 9);
- STEP(G, b, c, d, a, GET(13) + 0x5A827999, 13);
-
- STEP(G, a, b, c, d, GET( 2) + 0x5A827999, 3);
- STEP(G, d, a, b, c, GET( 6) + 0x5A827999, 5);
- STEP(G, c, d, a, b, GET(10) + 0x5A827999, 9);
- STEP(G, b, c, d, a, GET(14) + 0x5A827999, 13);
-
- STEP(G, a, b, c, d, GET( 3) + 0x5A827999, 3);
- STEP(G, d, a, b, c, GET( 7) + 0x5A827999, 5);
- STEP(G, c, d, a, b, GET(11) + 0x5A827999, 9);
- STEP(G, b, c, d, a, GET(15) + 0x5A827999, 13);
-
- /* Round 3 */
- STEP(H, a, b, c, d, GET( 0) + 0x6ED9EBA1, 3);
- STEP(H, d, a, b, c, GET( 8) + 0x6ED9EBA1, 9);
- STEP(H, c, d, a, b, GET( 4) + 0x6ED9EBA1, 11);
- STEP(H, b, c, d, a, GET(12) + 0x6ED9EBA1, 15);
-
- STEP(H, a, b, c, d, GET( 2) + 0x6ED9EBA1, 3);
- STEP(H, d, a, b, c, GET(10) + 0x6ED9EBA1, 9);
- STEP(H, c, d, a, b, GET( 6) + 0x6ED9EBA1, 11);
- STEP(H, b, c, d, a, GET(14) + 0x6ED9EBA1, 15);
-
- STEP(H, a, b, c, d, GET( 1) + 0x6ED9EBA1, 3);
- STEP(H, d, a, b, c, GET( 9) + 0x6ED9EBA1, 9);
- STEP(H, c, d, a, b, GET( 5) + 0x6ED9EBA1, 11);
- STEP(H, b, c, d, a, GET(13) + 0x6ED9EBA1, 15);
-
- STEP(H, a, b, c, d, GET( 3) + 0x6ED9EBA1, 3);
- STEP(H, d, a, b, c, GET(11) + 0x6ED9EBA1, 9);
- STEP(H, c, d, a, b, GET( 7) + 0x6ED9EBA1, 11);
- STEP(H, b, c, d, a, GET(15) + 0x6ED9EBA1, 15);
-
- a += saved_a;
- b += saved_b;
- c += saved_c;
- d += saved_d;
-
- ptr += 64;
- } while (size -= 64);
+ {
+ saved_a = a;
+ saved_b = b;
+ saved_c = c;
+ saved_d = d;
+
+ /* Round 1 */
+ STEP(F, a, b, c, d, SET( 0), 3);
+ STEP(F, d, a, b, c, SET( 1), 7);
+ STEP(F, c, d, a, b, SET( 2), 11);
+ STEP(F, b, c, d, a, SET( 3), 19);
+
+ STEP(F, a, b, c, d, SET( 4), 3);
+ STEP(F, d, a, b, c, SET( 5), 7);
+ STEP(F, c, d, a, b, SET( 6), 11);
+ STEP(F, b, c, d, a, SET( 7), 19);
+
+ STEP(F, a, b, c, d, SET( 8), 3);
+ STEP(F, d, a, b, c, SET( 9), 7);
+ STEP(F, c, d, a, b, SET(10), 11);
+ STEP(F, b, c, d, a, SET(11), 19);
+
+ STEP(F, a, b, c, d, SET(12), 3);
+ STEP(F, d, a, b, c, SET(13), 7);
+ STEP(F, c, d, a, b, SET(14), 11);
+ STEP(F, b, c, d, a, SET(15), 19);
+
+ /* Round 2 */
+ STEP(G, a, b, c, d, GET( 0) + 0x5A827999, 3);
+ STEP(G, d, a, b, c, GET( 4) + 0x5A827999, 5);
+ STEP(G, c, d, a, b, GET( 8) + 0x5A827999, 9);
+ STEP(G, b, c, d, a, GET(12) + 0x5A827999, 13);
+
+ STEP(G, a, b, c, d, GET( 1) + 0x5A827999, 3);
+ STEP(G, d, a, b, c, GET( 5) + 0x5A827999, 5);
+ STEP(G, c, d, a, b, GET( 9) + 0x5A827999, 9);
+ STEP(G, b, c, d, a, GET(13) + 0x5A827999, 13);
+
+ STEP(G, a, b, c, d, GET( 2) + 0x5A827999, 3);
+ STEP(G, d, a, b, c, GET( 6) + 0x5A827999, 5);
+ STEP(G, c, d, a, b, GET(10) + 0x5A827999, 9);
+ STEP(G, b, c, d, a, GET(14) + 0x5A827999, 13);
+
+ STEP(G, a, b, c, d, GET( 3) + 0x5A827999, 3);
+ STEP(G, d, a, b, c, GET( 7) + 0x5A827999, 5);
+ STEP(G, c, d, a, b, GET(11) + 0x5A827999, 9);
+ STEP(G, b, c, d, a, GET(15) + 0x5A827999, 13);
+
+ /* Round 3 */
+ STEP(H, a, b, c, d, GET( 0) + 0x6ED9EBA1, 3);
+ STEP(H, d, a, b, c, GET( 8) + 0x6ED9EBA1, 9);
+ STEP(H, c, d, a, b, GET( 4) + 0x6ED9EBA1, 11);
+ STEP(H, b, c, d, a, GET(12) + 0x6ED9EBA1, 15);
+
+ STEP(H, a, b, c, d, GET( 2) + 0x6ED9EBA1, 3);
+ STEP(H, d, a, b, c, GET(10) + 0x6ED9EBA1, 9);
+ STEP(H, c, d, a, b, GET( 6) + 0x6ED9EBA1, 11);
+ STEP(H, b, c, d, a, GET(14) + 0x6ED9EBA1, 15);
+
+ STEP(H, a, b, c, d, GET( 1) + 0x6ED9EBA1, 3);
+ STEP(H, d, a, b, c, GET( 9) + 0x6ED9EBA1, 9);
+ STEP(H, c, d, a, b, GET( 5) + 0x6ED9EBA1, 11);
+ STEP(H, b, c, d, a, GET(13) + 0x6ED9EBA1, 15);
+
+ STEP(H, a, b, c, d, GET( 3) + 0x6ED9EBA1, 3);
+ STEP(H, d, a, b, c, GET(11) + 0x6ED9EBA1, 9);
+ STEP(H, c, d, a, b, GET( 7) + 0x6ED9EBA1, 11);
+ STEP(H, b, c, d, a, GET(15) + 0x6ED9EBA1, 15);
+
+ a += saved_a;
+ b += saved_b;
+ c += saved_c;
+ d += saved_d;
+
+ ptr += 64;
+ }
+ while (size -= 64);
ctx->a = a;
ctx->b = b;
@@ -191,24 +192,27 @@ md4_process_bytes (const void *buffer, struct md4_ctx *ctx, size_t size)
used = saved_lo & 0x3f;
- if (used) {
- free = 64 - used;
+ if (used)
+ {
+ free = 64 - used;
- if (size < free) {
- memcpy(&ctx->buffer[used], buffer, size);
- return;
- }
+ if (size < free)
+ {
+ memcpy(&ctx->buffer[used], buffer, size);
+ return;
+ }
- memcpy(&ctx->buffer[used], buffer, free);
- buffer = (const unsigned char *) buffer + free;
- size -= free;
- body(ctx, ctx->buffer, 64);
- }
+ memcpy(&ctx->buffer[used], buffer, free);
+ buffer = (const unsigned char *) buffer + free;
+ size -= free;
+ body(ctx, ctx->buffer, 64);
+ }
- if (size >= 64) {
- buffer = body(ctx, buffer, size & ~(uint32_t)0x3f);
- size &= 0x3f;
- }
+ if (size >= 64)
+ {
+ buffer = body(ctx, buffer, size & ~(uint32_t)0x3f);
+ size &= 0x3f;
+ }
memcpy(ctx->buffer, buffer, size);
}
@@ -224,12 +228,13 @@ md4_finish_ctx (struct md4_ctx *ctx, void *resbuf)
free = 64 - used;
- if (free < 8) {
- memset(&ctx->buffer[used], 0, free);
- body(ctx, ctx->buffer, 64);
- used = 0;
- free = 64;
- }
+ if (free < 8)
+ {
+ memset(&ctx->buffer[used], 0, free);
+ body(ctx, ctx->buffer, 64);
+ used = 0;
+ free = 64;
+ }
memset(&ctx->buffer[used], 0, free - 8);
diff --git a/alg-sha256.c b/alg-sha256.c
index 79cf618..e97abaf 100644
--- a/alg-sha256.c
+++ b/alg-sha256.c
@@ -26,7 +26,8 @@
/* Constants for SHA256 from FIPS 180-2:4.2.2. */
-static const uint32_t K[64] = {
+static const uint32_t K[64] =
+{
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
@@ -228,7 +229,7 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx)
}
/* Process available complete blocks. */
- if (len > 64)
+ if (len > 64)
{
sha256_process_block (buffer, len & ~63u, ctx);
buffer = (const char *) buffer + (len & ~63u);
diff --git a/alg-sha512.c b/alg-sha512.c
index 2d37447..330e122 100644
--- a/alg-sha512.c
+++ b/alg-sha512.c
@@ -26,7 +26,8 @@
/* Constants for SHA512 from FIPS 180-2:4.2.3. */
-static const uint64_t K[80] = {
+static const uint64_t K[80] =
+{
UINT64_C (0x428a2f98d728ae22), UINT64_C (0x7137449123ef65cd),
UINT64_C (0xb5c0fbcfec4d3b2f), UINT64_C (0xe9b5dba58189dbbc),
UINT64_C (0x3956c25bf348b538), UINT64_C (0x59f111f1b605d019),
diff --git a/crypt-base.h b/crypt-base.h
index 1dc5fa9..af6df29 100644
--- a/crypt-base.h
+++ b/crypt-base.h
@@ -59,7 +59,7 @@
SETTING nor to any valid hashed passphrase. Otherwise, the string
will not begin with '*'. */
extern char *crypt (const char *__phrase, const char *__setting)
- __THROW __nonnull ((1, 2));
+__THROW __nonnull ((1, 2));
/* These sizes are chosen to make sizeof (struct crypt_data) add up to
exactly 32768 bytes. */
@@ -113,7 +113,7 @@ struct crypt_data
DATA->output. Otherwise, behaves exactly the same as crypt. */
extern char *crypt_r (const char *__phrase, const char *__setting,
struct crypt_data *restrict __data)
- __THROW __nonnull ((1, 2, 3));
+__THROW __nonnull ((1, 2, 3));
/* Another thread-safe version of crypt. Instead of writing to a
static storage area, the string returned by this function will be
@@ -125,7 +125,7 @@ extern char *crypt_r (const char *__phrase, const char *__setting,
still will never begin with '*'.) */
extern char *crypt_rn (const char *__phrase, const char *__setting,
void *__data, int __size)
- __THROW __nonnull ((1, 2, 3));
+__THROW __nonnull ((1, 2, 3));
/* Yet a third thread-safe version of crypt; this one works like
getline(3). *DATA must be either 0 or a pointer to memory
@@ -139,7 +139,7 @@ extern char *crypt_rn (const char *__phrase, const char *__setting,
a special string. */
extern char *crypt_ra (const char *__phrase, const char *__setting,
void **__data, int *__size)
- __THROW __nonnull ((1, 2, 3, 4));
+__THROW __nonnull ((1, 2, 3, 4));
/* Generate a string suitable for use as the setting when hashing a
@@ -164,7 +164,7 @@ extern char *crypt_ra (const char *__phrase, const char *__setting,
this function returns a null pointer. */
extern char *crypt_gensalt (const char *__prefix, unsigned long __count,
const char *__rbytes, int __nrbytes)
- __THROW;
+__THROW;
/* Thread-safe version of crypt_gensalt; instead of a
statically-allocated buffer, the generated setting string is
@@ -176,14 +176,14 @@ extern char *crypt_gensalt (const char *__prefix, unsigned long __count,
extern char *crypt_gensalt_rn (const char *__prefix, unsigned long __count,
const char *__rbytes, int __nrbytes,
char *__output, int __output_size)
- __THROW __nonnull ((5));
+__THROW __nonnull ((5));
/* Another thread-safe version of crypt_gensalt; the generated setting
string is in storage allocated by malloc, and should be deallocated
with free when it is no longer needed. */
extern char *crypt_gensalt_ra (const char *__prefix, unsigned long __count,
const char *__rbytes, int __nrbytes)
- __THROW;
+__THROW;
/*TRAILER*/
diff --git a/crypt-bcrypt.c b/crypt-bcrypt.c
index b4aac0b..41482b5 100644
--- a/crypt-bcrypt.c
+++ b/crypt-bcrypt.c
@@ -83,7 +83,8 @@ typedef struct
* Magic IV for 64 Blowfish encryptions that we do at the end.
* The string is "OrpheanBeholderScryDoubt" on big-endian.
*/
-static const BF_word BF_magic_w[6] = {
+static const BF_word BF_magic_w[6] =
+{
0x4F727068, 0x65616E42, 0x65686F6C,
0x64657253, 0x63727944, 0x6F756274
};
@@ -91,7 +92,8 @@ static const BF_word BF_magic_w[6] = {
/*
* P-box and S-box tables initialized with digits of Pi.
*/
-static const BF_ctx BF_init_state = {
+static const BF_ctx BF_init_state =
+{
{
{
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
@@ -370,7 +372,8 @@ static const BF_ctx BF_init_state = {
static const unsigned char BF_itoa64[64 + 1] =
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-static const unsigned char BF_atoi64[0x60] = {
+static const unsigned char BF_atoi64[0x60] =
+{
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 64, 64, 64, 64, 64,
64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
@@ -567,41 +570,41 @@ BF_set_key (const char *key, BF_key expanded, BF_key initial,
BF_word safety, sign, diff, tmp[2];
BF_word_signed stmp;
-/*
- * There was a sign extension bug in older revisions of this function. While
- * we would have liked to simply fix the bug and move on, we have to provide
- * a backwards compatibility feature (essentially the bug) for some systems and
- * a safety measure for some others. The latter is needed because for certain
- * multiple inputs to the buggy algorithm there exist easily found inputs to
- * the correct algorithm that produce the same hash. Thus, we optionally
- * deviate from the correct algorithm just enough to avoid such collisions.
- * While the bug itself affected the majority of passwords containing
- * characters with the 8th bit set (although only a percentage of those in a
- * collision-producing way), the anti-collision safety measure affects
- * only a subset of passwords containing the '\xff' character (not even all of
- * those passwords, just some of them). This character is not found in valid
- * UTF-8 sequences and is rarely used in popular 8-bit character encodings.
- * Thus, the safety measure is unlikely to cause much annoyance, and is a
- * reasonable tradeoff to use when authenticating against existing hashes that
- * are not reliably known to have been computed with the correct algorithm.
- *
- * We use an approach that tries to minimize side-channel leaks of password
- * information - that is, we mostly use fixed-cost bitwise operations instead
- * of branches or table lookups. (One conditional branch based on password
- * length remains. It is not part of the bug aftermath, though, and is
- * difficult and possibly unreasonable to avoid given the use of C strings by
- * the caller, which results in similar timing leaks anyway.)
- *
- * For actual implementation, we set an array index in the variable "bug"
- * (0 means no bug, 1 means sign extension bug emulation) and a flag in the
- * variable "safety" (bit 16 is set when the safety measure is requested).
- * Valid combinations of settings are:
- *
- * Prefix "$2a$": bug = 0, safety = 0x10000
- * Prefix "$2b$": bug = 0, safety = 0
- * Prefix "$2x$": bug = 1, safety = 0
- * Prefix "$2y$": bug = 0, safety = 0
- */
+ /*
+ * There was a sign extension bug in older revisions of this function. While
+ * we would have liked to simply fix the bug and move on, we have to provide
+ * a backwards compatibility feature (essentially the bug) for some systems and
+ * a safety measure for some others. The latter is needed because for certain
+ * multiple inputs to the buggy algorithm there exist easily found inputs to
+ * the correct algorithm that produce the same hash. Thus, we optionally
+ * deviate from the correct algorithm just enough to avoid such collisions.
+ * While the bug itself affected the majority of passwords containing
+ * characters with the 8th bit set (although only a percentage of those in a
+ * collision-producing way), the anti-collision safety measure affects
+ * only a subset of passwords containing the '\xff' character (not even all of
+ * those passwords, just some of them). This character is not found in valid
+ * UTF-8 sequences and is rarely used in popular 8-bit character encodings.
+ * Thus, the safety measure is unlikely to cause much annoyance, and is a
+ * reasonable tradeoff to use when authenticating against existing hashes that
+ * are not reliably known to have been computed with the correct algorithm.
+ *
+ * We use an approach that tries to minimize side-channel leaks of password
+ * information - that is, we mostly use fixed-cost bitwise operations instead
+ * of branches or table lookups. (One conditional branch based on password
+ * length remains. It is not part of the bug aftermath, though, and is
+ * difficult and possibly unreasonable to avoid given the use of C strings by
+ * the caller, which results in similar timing leaks anyway.)
+ *
+ * For actual implementation, we set an array index in the variable "bug"
+ * (0 means no bug, 1 means sign extension bug emulation) and a flag in the
+ * variable "safety" (bit 16 is set when the safety measure is requested).
+ * Valid combinations of settings are:
+ *
+ * Prefix "$2a$": bug = 0, safety = 0x10000
+ * Prefix "$2b$": bug = 0, safety = 0
+ * Prefix "$2x$": bug = 1, safety = 0
+ * Prefix "$2y$": bug = 0, safety = 0
+ */
bug = (unsigned int) flags & 1;
safety = ((BF_word) flags & 2) << 15;
@@ -617,12 +620,12 @@ BF_set_key (const char *key, BF_key expanded, BF_key initial,
tmp[1] <<= 8;
stmp = (BF_word_signed) (signed char) *ptr; /* bug */
tmp[1] |= (BF_word) stmp; /* two steps avoid GCC 6 spurious warning */
-/*
- * Sign extension in the first char has no effect - nothing to overwrite yet,
- * and those extra 24 bits will be fully shifted out of the 32-bit word. For
- * chars 2, 3, 4 in each four-char block, we set bit 7 of "sign" if sign
- * extension in tmp[1] occurs. Once this flag is set, it remains set.
- */
+ /*
+ * Sign extension in the first char has no effect - nothing to overwrite yet,
+ * and those extra 24 bits will be fully shifted out of the 32-bit word. For
+ * chars 2, 3, 4 in each four-char block, we set bit 7 of "sign" if sign
+ * extension in tmp[1] occurs. Once this flag is set, it remains set.
+ */
if (j)
sign |= tmp[1] & 0x80;
if (!*ptr)
@@ -636,36 +639,37 @@ BF_set_key (const char *key, BF_key expanded, BF_key initial,
initial[i] = BF_init_state.P[i] ^ tmp[bug];
}
-/*
- * At this point, "diff" is zero iff the correct and buggy algorithms produced
- * exactly the same result. If so and if "sign" is non-zero, which indicates
- * that there was a non-benign sign extension, this means that we have a
- * collision between the correctly computed hash for this password and a set of
- * passwords that could be supplied to the buggy algorithm. Our safety measure
- * is meant to protect from such many-buggy to one-correct collisions, by
- * deviating from the correct algorithm in such cases. Let's check for this.
- */
+ /*
+ * At this point, "diff" is zero iff the correct and buggy algorithms produced
+ * exactly the same result. If so and if "sign" is non-zero, which indicates
+ * that there was a non-benign sign extension, this means that we have a
+ * collision between the correctly computed hash for this password and a set of
+ * passwords that could be supplied to the buggy algorithm. Our safety measure
+ * is meant to protect from such many-buggy to one-correct collisions, by
+ * deviating from the correct algorithm in such cases. Let's check for this.
+ */
diff |= diff >> 16; /* still zero iff exact match */
diff &= 0xffff; /* ditto */
diff += 0xffff; /* bit 16 set iff "diff" was non-zero (on non-match) */
sign <<= 9; /* move the non-benign sign extension flag to bit 16 */
sign &= ~diff & safety; /* action needed? */
-/*
- * If we have determined that we need to deviate from the correct algorithm,
- * flip bit 16 in initial expanded key. (The choice of 16 is arbitrary, but
- * let's stick to it now. It came out of the approach we used above, and it's
- * not any worse than any other choice we could make.)
- *
- * It is crucial that we don't do the same to the expanded key used in the main
- * Eksblowfish loop. By doing it to only one of these two, we deviate from a
- * state that could be directly specified by a password to the buggy algorithm
- * (and to the fully correct one as well, but that's a side-effect).
- */
+ /*
+ * If we have determined that we need to deviate from the correct algorithm,
+ * flip bit 16 in initial expanded key. (The choice of 16 is arbitrary, but
+ * let's stick to it now. It came out of the approach we used above, and it's
+ * not any worse than any other choice we could make.)
+ *
+ * It is crucial that we don't do the same to the expanded key used in the main
+ * Eksblowfish loop. By doing it to only one of these two, we deviate from a
+ * state that could be directly specified by a password to the buggy algorithm
+ * (and to the fully correct one as well, but that's a side-effect).
+ */
initial[0] ^= sign;
}
-static const unsigned char flags_by_subtype[26] = {
+static const unsigned char flags_by_subtype[26] =
+{
2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0
};
@@ -745,7 +749,7 @@ BF_crypt (const char *key, const char *setting, unsigned char *output,
BF_set_key (key, data->expanded_key, data->ctx.P,
flags_by_subtype[(unsigned int) (unsigned char) setting[2] -
- 'a']);
+ 'a']);
memcpy (data->ctx.S, BF_init_state.S, sizeof (data->ctx.S));
@@ -835,8 +839,8 @@ BF_crypt (const char *key, const char *setting, unsigned char *output,
BF_atoi64[(int) setting[BF_SETTING_LENGTH - 1] -
0x20] & 0x30];
-/* This has to be bug-compatible with the original implementation, so
- * only encode 23 of the 24 bytes. :-) */
+ /* This has to be bug-compatible with the original implementation, so
+ * only encode 23 of the 24 bytes. :-) */
BF_swap (data->binary.output, 6);
BF_encode (&output[BF_SETTING_LENGTH], data->binary.output, 23);
output[BF_HASH_LENGTH - 1] = '\0';
@@ -892,14 +896,15 @@ crypt_bcrypt_rn (const char *key, const char *setting,
static const char test_key[] = "8b \xd0\xc1\xd2\xcf\xcc\xd8";
static const char test_setting_init[] = "$2a$00$abcdefghijklmnopqrstuu";
- static const char *const test_hashes[2] = {
+ static const char *const test_hashes[2] =
+ {
"i1D709vfamulimlGcq0qq3UvuUasvEa\0\x55", /* 'a', 'b', 'y' */
"VUrPmXD6q/nVSSp7pNDhCR9071IfIRe\0\x55" /* 'x' */
};
const char *test_hash = test_hashes[0];
char test_setting[BF_SETTING_LENGTH];
unsigned int flags = flags_by_subtype[(unsigned int) (unsigned char)
- setting[2] - 'a'];
+ setting[2] - 'a'];
bool ok;
memcpy (test_setting, test_setting_init, BF_SETTING_LENGTH);
@@ -921,7 +926,7 @@ crypt_bcrypt_rn (const char *key, const char *setting,
BF_set_key (k, ye, yi, 4); /* $2y$ */
ai[0] ^= 0x10000; /* undo the safety (for comparison) */
ok = ok && ai[0] == 0xdb9c59bc && ye[17] == 0x33343500 &&
- !memcmp (ae, ye, sizeof (ae)) && !memcmp (ai, yi, sizeof (ai));
+ !memcmp (ae, ye, sizeof (ae)) && !memcmp (ai, yi, sizeof (ai));
}
if (!ok)
diff --git a/crypt-des.c b/crypt-des.c
index 4c71e43..5e34498 100644
--- a/crypt-des.c
+++ b/crypt-des.c
@@ -271,7 +271,7 @@ crypt_des_trd_or_big_rn (const char *phrase, const char *setting,
void *scratch, size_t s_size)
{
(strlen (setting) > 13 ? crypt_des_big_rn : crypt_des_trd_rn)
- (phrase, setting, output, o_size, scratch, s_size);
+ (phrase, setting, output, o_size, scratch, s_size);
}
/* crypt_rn() entry point for BSD-style extended DES hashes. These
@@ -368,8 +368,8 @@ gensalt_des_trd_rn (unsigned long count,
void
gensalt_des_xbsd_rn (unsigned long count,
- const uint8_t *rbytes, size_t nrbytes,
- uint8_t *output, size_t output_size)
+ const uint8_t *rbytes, size_t nrbytes,
+ uint8_t *output, size_t output_size)
{
if (output_size < 1 + 4 + 4 + 1)
{
diff --git a/crypt-md5.c b/crypt-md5.c
index 7943541..3926f97 100644
--- a/crypt-md5.c
+++ b/crypt-md5.c
@@ -139,7 +139,7 @@ crypt_md5_rn (const char *phrase, const char *setting,
what was intended but we have to follow this to be compatible. */
for (cnt = phrase_len; cnt > 0; cnt >>= 1)
md5_process_bytes ((cnt & 1) != 0 ? (const char *) result : phrase, 1,
- ctx);
+ ctx);
/* Create intermediate result. */
md5_finish_ctx (ctx, result);
diff --git a/crypt-nthash.c b/crypt-nthash.c
index 7d0cfe2..0f16bcb 100644
--- a/crypt-nthash.c
+++ b/crypt-nthash.c
@@ -66,16 +66,16 @@ crypt_nthash_rn (const char *phrase,
if ((o_size < 4 + 32) ||
(s_size < sizeof (struct md4_ctx)))
- {
- errno = ERANGE;
- return;
- }
+ {
+ errno = ERANGE;
+ return;
+ }
if (strncmp (setting, magic, strlen (magic)))
- {
- errno = EINVAL;
- return;
- }
+ {
+ errno = EINVAL;
+ return;
+ }
memset (unipw, 0, sizeof(unipw));
/* convert to unicode (thanx Archie) */
@@ -90,10 +90,11 @@ crypt_nthash_rn (const char *phrase,
output = (uint8_t *)stpcpy ((char *)output, magic);
*output++ = '$';
- for (i = 0; i < 16; i++) {
- *output++ = (uint8_t)hexconvtab[hash[i] >> 4];
- *output++ = (uint8_t)hexconvtab[hash[i] & 0xf];
- }
+ for (i = 0; i < 16; i++)
+ {
+ *output++ = (uint8_t)hexconvtab[hash[i] >> 4];
+ *output++ = (uint8_t)hexconvtab[hash[i] & 0xf];
+ }
*output = '\0';
}
@@ -121,22 +122,22 @@ gensalt_nthash_rn (unsigned long count,
to calculate the MD4 hash used in the
fake salt. */
if ((o_size < 29) || (nrbytes < 1))
- {
- errno = ERANGE;
- return;
- }
+ {
+ errno = ERANGE;
+ return;
+ }
if (count < 20)
count = 20;
md4_init_ctx (&ctx);
for (i = 0; i < count; i++)
- {
- md4_process_bytes (salt, &ctx, (i % 15) + 1);
- md4_process_bytes (rbytes, &ctx, nrbytes);
- md4_process_bytes (salt, &ctx, 15);
- md4_process_bytes (salt, &ctx, 15 - (i % 15));
- }
+ {
+ md4_process_bytes (salt, &ctx, (i % 15) + 1);
+ md4_process_bytes (rbytes, &ctx, nrbytes);
+ md4_process_bytes (salt, &ctx, 15);
+ md4_process_bytes (salt, &ctx, 15 - (i % 15));
+ }
md4_finish_ctx (&ctx, &hashbuf);
for (i = 0; i < 7; i++)
diff --git a/crypt-obsolete.h b/crypt-obsolete.h
index 3fcc856..d1acdea 100644
--- a/crypt-obsolete.h
+++ b/crypt-obsolete.h
@@ -26,19 +26,19 @@
/* Setup DES tables according KEY. */
extern void setkey (const char *__key)
- __nonnull ((1));
+__nonnull ((1));
extern void setkey_r (const char *__key,
struct crypt_data *restrict __data)
- __nonnull ((1, 2));
+__nonnull ((1, 2));
/* Encrypt data in BLOCK in place if EDFLAG is zero; otherwise decrypt
block in place. */
extern void encrypt (char *__block, int __edflag)
- __nonnull ((1));
+__nonnull ((1));
extern void encrypt_r (char *__block, int __edflag,
struct crypt_data *restrict __data)
- __nonnull ((1, 3));
+__nonnull ((1, 3));
#endif /* crypt-obsolete.h */
diff --git a/crypt.c b/crypt.c
index c26d4c1..a07b7af 100644
--- a/crypt.c
+++ b/crypt.c
@@ -77,7 +77,8 @@ struct hashfn
/* This table should always begin with the algorithm that should be used
for new encryptions. */
-static const struct hashfn tagged_hashes[] = {
+static const struct hashfn tagged_hashes[] =
+{
/* bcrypt */
{ "$2a$", crypt_bcrypt_rn, gensalt_bcrypt_a_rn },
{ "$2b$", crypt_bcrypt_rn, gensalt_bcrypt_b_rn },
@@ -96,12 +97,14 @@ static const struct hashfn tagged_hashes[] = {
#if ENABLE_WEAK_HASHES
/* BSD-style extended DES */
-static const struct hashfn bsdi_extended_hash = {
+static const struct hashfn bsdi_extended_hash =
+{
"_", crypt_des_xbsd_rn, gensalt_des_xbsd_rn
};
/* Traditional DES or bigcrypt-style extended DES */
-static const struct hashfn traditional_hash = {
+static const struct hashfn traditional_hash =
+{
"", crypt_des_trd_or_big_rn, gensalt_des_trd_rn
};
@@ -206,10 +209,10 @@ struct crypt_fn_args
#if UINTPTR_MAX == UINT_MAX
static_assert (sizeof (uintptr_t) == sizeof (int),
- "UINTPTR_MAX matches UINT_MAX but sizeof (uintptr_t) != sizeof (int)");
+ "UINTPTR_MAX matches UINT_MAX but sizeof (uintptr_t) != sizeof (int)");
static_assert (sizeof (struct crypt_fn_args *) == sizeof (int),
- "UINTPTR_MAX matches UINT_MAX but sizeof (crypt_fn_args *) != sizeof (int)");
+ "UINTPTR_MAX matches UINT_MAX but sizeof (crypt_fn_args *) != sizeof (int)");
#define SWIZZLE_PTR(ptr) 1, ((int)(uintptr_t)(ptr))
#define UNSWIZZLE_PTR(val) ((struct crypt_fn_args *)(uintptr_t)(val))
@@ -218,10 +221,10 @@ static_assert (sizeof (struct crypt_fn_args *) == sizeof (int),
#elif UINTPTR_MAX == ULONG_MAX
static_assert (sizeof (uintptr_t) == 2*sizeof (int),
- "UINTPTR_MAX matches ULONG_MAX but sizeof (uintptr_t) != 2*sizeof (int)");
+ "UINTPTR_MAX matches ULONG_MAX but sizeof (uintptr_t) != 2*sizeof (int)");
static_assert (sizeof (struct crypt_fn_args *) == 2*sizeof (int),
-"UINTPTR_MAX matches ULONG_MAX but sizeof (crypt_fn_args *) != 2*sizeof (int)");
+ "UINTPTR_MAX matches ULONG_MAX but sizeof (crypt_fn_args *) != 2*sizeof (int)");
#define SWIZZLE_PTR(ptr) 2, \
(int)((((uintptr_t)ptr) >> (sizeof(int)*CHAR_BIT)) & UINT_MAX), \
diff --git a/gen-des-tables.c b/gen-des-tables.c
index 371541a..cf2b76f 100644
--- a/gen-des-tables.c
+++ b/gen-des-tables.c
@@ -45,27 +45,30 @@
#include <inttypes.h>
#include <stdio.h>
-static const uint8_t IP[64] = {
- 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
- 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
- 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
- 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
+static const uint8_t IP[64] =
+{
+ 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
+ 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
+ 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
+ 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
};
static uint8_t inv_key_perm[64];
-static const uint8_t key_perm[56] = {
- 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
- 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
- 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
- 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
+static const uint8_t key_perm[56] =
+{
+ 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
+ 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
+ 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
+ 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
};
static uint8_t inv_comp_perm[56];
-static const uint8_t comp_perm[48] = {
- 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
- 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
- 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
- 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
+static const uint8_t comp_perm[48] =
+{
+ 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
+ 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
+ 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
+ 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
};
/*
@@ -73,61 +76,63 @@ static const uint8_t comp_perm[48] = {
*/
static uint8_t u_sbox[8][64];
-static const uint8_t sbox[8][64] = {
- {
- 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
- 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
- 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
- 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
- },
- {
- 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
- 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
- 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
- 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
- },
- {
- 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
- 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
- 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
- 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
- },
- {
- 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
- 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
- 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
- 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
- },
- {
- 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
- 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
- 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
- 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
- },
- {
- 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
- 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
- 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
- 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
- },
- {
- 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
- 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
- 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
- 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
- },
- {
- 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
- 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
- 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
- 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
- }
+static const uint8_t sbox[8][64] =
+{
+ {
+ 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
+ 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
+ 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
+ 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
+ },
+ {
+ 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
+ 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
+ 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
+ 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
+ },
+ {
+ 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
+ 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
+ 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
+ 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
+ },
+ {
+ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
+ 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
+ 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
+ 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
+ },
+ {
+ 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
+ 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
+ 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
+ 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
+ },
+ {
+ 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
+ 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
+ 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
+ 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
+ },
+ {
+ 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
+ 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
+ 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
+ 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
+ },
+ {
+ 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
+ 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
+ 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
+ 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
+ }
};
static uint8_t un_pbox[32];
-static const uint8_t pbox[32] = {
- 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
- 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
+static const uint8_t pbox[32] =
+{
+ 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
+ 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
};
static const uint32_t *bits28, *bits24;
@@ -135,18 +140,18 @@ static uint8_t init_perm[64], final_perm[64];
static const uint32_t bits32[32] =
{
- 0x80000000, 0x40000000, 0x20000000, 0x10000000,
- 0x08000000, 0x04000000, 0x02000000, 0x01000000,
- 0x00800000, 0x00400000, 0x00200000, 0x00100000,
- 0x00080000, 0x00040000, 0x00020000, 0x00010000,
- 0x00008000, 0x00004000, 0x00002000, 0x00001000,
- 0x00000800, 0x00000400, 0x00000200, 0x00000100,
- 0x00000080, 0x00000040, 0x00000020, 0x00000010,
- 0x00000008, 0x00000004, 0x00000002, 0x00000001
+ 0x80000000, 0x40000000, 0x20000000, 0x10000000,
+ 0x08000000, 0x04000000, 0x02000000, 0x01000000,
+ 0x00800000, 0x00400000, 0x00200000, 0x00100000,
+ 0x00080000, 0x00040000, 0x00020000, 0x00010000,
+ 0x00008000, 0x00004000, 0x00002000, 0x00001000,
+ 0x00000800, 0x00000400, 0x00000200, 0x00000100,
+ 0x00000080, 0x00000040, 0x00000020, 0x00000010,
+ 0x00000008, 0x00000004, 0x00000002, 0x00000001
};
static const uint8_t bits8[8] =
- { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+{ 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
static uint8_t m_sbox_[4][4096];
static uint32_t ip_maskl_[8][256], ip_maskr_[8][256];
@@ -158,126 +163,141 @@ static uint32_t psbox_[4][256];
static void
des_init(void)
{
- int i, j, b, k, inbit, obit;
- uint32_t *p, *il, *ir, *fl, *fr;
+ int i, j, b, k, inbit, obit;
+ uint32_t *p, *il, *ir, *fl, *fr;
- bits24 = (bits28 = bits32 + 4) + 4;
+ bits24 = (bits28 = bits32 + 4) + 4;
- /*
- * Invert the S-boxes, reordering the input bits.
- */
- for (i = 0; i < 8; i++)
- for (j = 0; j < 64; j++) {
- b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
- u_sbox[i][j] = sbox[i][b];
- }
+ /*
+ * Invert the S-boxes, reordering the input bits.
+ */
+ for (i = 0; i < 8; i++)
+ for (j = 0; j < 64; j++)
+ {
+ b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
+ u_sbox[i][j] = sbox[i][b];
+ }
- /*
- * Convert the inverted S-boxes into 4 arrays of 8 bits.
- * Each will handle 12 bits of the S-box input.
- */
- for (b = 0; b < 4; b++)
- for (i = 0; i < 64; i++)
- for (j = 0; j < 64; j++)
- m_sbox_[b][(i << 6) | j] =
- (uint8_t)((u_sbox[(b << 1)][i] << 4) |
- u_sbox[(b << 1) + 1][j]);
+ /*
+ * Convert the inverted S-boxes into 4 arrays of 8 bits.
+ * Each will handle 12 bits of the S-box input.
+ */
+ for (b = 0; b < 4; b++)
+ for (i = 0; i < 64; i++)
+ for (j = 0; j < 64; j++)
+ m_sbox_[b][(i << 6) | j] =
+ (uint8_t)((u_sbox[(b << 1)][i] << 4) |
+ u_sbox[(b << 1) + 1][j]);
- /*
- * Set up the initial & final permutations into a useful form, and
- * initialise the inverted key permutation.
- */
- for (i = 0; i < 64; i++) {
- final_perm[i] = (uint8_t)(IP[i] - 1);
- init_perm[final_perm[i]] = (uint8_t)i;
- inv_key_perm[i] = 255;
- }
+ /*
+ * Set up the initial & final permutations into a useful form, and
+ * initialise the inverted key permutation.
+ */
+ for (i = 0; i < 64; i++)
+ {
+ final_perm[i] = (uint8_t)(IP[i] - 1);
+ init_perm[final_perm[i]] = (uint8_t)i;
+ inv_key_perm[i] = 255;
+ }
- /*
- * Invert the key permutation and initialise the inverted key
- * compression permutation.
- */
- for (i = 0; i < 56; i++) {
- inv_key_perm[key_perm[i] - 1] = (uint8_t)i;
- inv_comp_perm[i] = 255;
- }
+ /*
+ * Invert the key permutation and initialise the inverted key
+ * compression permutation.
+ */
+ for (i = 0; i < 56; i++)
+ {
+ inv_key_perm[key_perm[i] - 1] = (uint8_t)i;
+ inv_comp_perm[i] = 255;
+ }
- /*
- * Invert the key compression permutation.
- */
- for (i = 0; i < 48; i++) {
- inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i;
- }
+ /*
+ * Invert the key compression permutation.
+ */
+ for (i = 0; i < 48; i++)
+ {
+ inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i;
+ }
- /*
- * Set up the OR-mask arrays for the initial and final permutations,
- * and for the key initial and compression permutations.
- */
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 256; i++) {
- *(il = &ip_maskl_[k][i]) = 0L;
- *(ir = &ip_maskr_[k][i]) = 0L;
- *(fl = &fp_maskl_[k][i]) = 0L;
- *(fr = &fp_maskr_[k][i]) = 0L;
- for (j = 0; j < 8; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j]) {
- if ((obit = init_perm[inbit]) < 32)
- *il |= bits32[obit];
- else
- *ir |= bits32[obit-32];
- if ((obit = final_perm[inbit]) < 32)
- *fl |= bits32[obit];
- else
- *fr |= bits32[obit - 32];
- }
- }
- }
- for (i = 0; i < 128; i++) {
- *(il = &key_perm_maskl_[k][i]) = 0L;
- *(ir = &key_perm_maskr_[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit = inv_key_perm[inbit]) == 255)
- continue;
- if (obit < 28)
- *il |= bits28[obit];
- else
- *ir |= bits28[obit - 28];
- }
- }
- *(il = &comp_maskl_[k][i]) = 0L;
- *(ir = &comp_maskr_[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 7 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit=inv_comp_perm[inbit]) == 255)
- continue;
- if (obit < 24)
- *il |= bits24[obit];
- else
- *ir |= bits24[obit - 24];
- }
- }
- }
- }
+ /*
+ * Set up the OR-mask arrays for the initial and final permutations,
+ * and for the key initial and compression permutations.
+ */
+ for (k = 0; k < 8; k++)
+ {
+ for (i = 0; i < 256; i++)
+ {
+ *(il = &ip_maskl_[k][i]) = 0L;
+ *(ir = &ip_maskr_[k][i]) = 0L;
+ *(fl = &fp_maskl_[k][i]) = 0L;
+ *(fr = &fp_maskr_[k][i]) = 0L;
+ for (j = 0; j < 8; j++)
+ {
+ inbit = 8 * k + j;
+ if (i & bits8[j])
+ {
+ if ((obit = init_perm[inbit]) < 32)
+ *il |= bits32[obit];
+ else
+ *ir |= bits32[obit-32];
+ if ((obit = final_perm[inbit]) < 32)
+ *fl |= bits32[obit];
+ else
+ *fr |= bits32[obit - 32];
+ }
+ }
+ }
+ for (i = 0; i < 128; i++)
+ {
+ *(il = &key_perm_maskl_[k][i]) = 0L;
+ *(ir = &key_perm_maskr_[k][i]) = 0L;
+ for (j = 0; j < 7; j++)
+ {
+ inbit = 8 * k + j;
+ if (i & bits8[j + 1])
+ {
+ if ((obit = inv_key_perm[inbit]) == 255)
+ continue;
+ if (obit < 28)
+ *il |= bits28[obit];
+ else
+ *ir |= bits28[obit - 28];
+ }
+ }
+ *(il = &comp_maskl_[k][i]) = 0L;
+ *(ir = &comp_maskr_[k][i]) = 0L;
+ for (j = 0; j < 7; j++)
+ {
+ inbit = 7 * k + j;
+ if (i & bits8[j + 1])
+ {
+ if ((obit=inv_comp_perm[inbit]) == 255)
+ continue;
+ if (obit < 24)
+ *il |= bits24[obit];
+ else
+ *ir |= bits24[obit - 24];
+ }
+ }
+ }
+ }
- /*
- * Invert the P-box permutation, and convert into OR-masks for
- * handling the output of the S-box arrays setup above.
- */
- for (i = 0; i < 32; i++)
- un_pbox[pbox[i] - 1] = (uint8_t)i;
+ /*
+ * Invert the P-box permutation, and convert into OR-masks for
+ * handling the output of the S-box arrays setup above.
+ */
+ for (i = 0; i < 32; i++)
+ un_pbox[pbox[i] - 1] = (uint8_t)i;
- for (b = 0; b < 4; b++)
- for (i = 0; i < 256; i++) {
- *(p = &psbox_[b][i]) = 0L;
- for (j = 0; j < 8; j++) {
- if (i & bits8[j])
- *p |= bits32[un_pbox[8 * b + j]];
- }
- }
+ for (b = 0; b < 4; b++)
+ for (i = 0; i < 256; i++)
+ {
+ *(p = &psbox_[b][i]) = 0L;
+ for (j = 0; j < 8; j++)
+ {
+ if (i & bits8[j])
+ *p |= bits32[un_pbox[8 * b + j]];
+ }
+ }
}
static void
diff --git a/test-alg-des.c b/test-alg-des.c
index 283e4d1..f596c1f 100644
--- a/test-alg-des.c
+++ b/test-alg-des.c
@@ -27,9 +27,9 @@ report_failure (size_t n, bool decrypt,
v_print (tc->key);
fputs (" exp ", stdout);
if (decrypt)
- v_print (tc->plain);
+ v_print (tc->plain);
else
- v_print (tc->answer);
+ v_print (tc->answer);
fputs (" got ", stdout);
v_print (got);
putchar ('\n');
diff --git a/test-alg-md4.c b/test-alg-md4.c
index c00c522..fe4f59e 100644
--- a/test-alg-md4.c
+++ b/test-alg-md4.c
@@ -9,24 +9,38 @@ static const struct
const char *input;
const char result[16];
} tests[] =
+{
+ /* Test vectors as defined in RFC 1320, appendix A, section 5.
+ https://tools.ietf.org/html/rfc1320#appendix-A.5 */
+ {
+ "",
+ "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0"
+ },
+ {
+ "a",
+ "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb\x24"
+ },
+ {
+ "abc",
+ "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"
+ },
+ {
+ "message digest",
+ "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01\x4b"
+ },
+ {
+ "abcdefghijklmnopqrstuvwxyz",
+ "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d\xa9"
+ },
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4"
+ },
{
- /* Test vectors as defined in RFC 1320, appendix A, section 5.
- https://tools.ietf.org/html/rfc1320#appendix-A.5 */
- { "",
- "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0" },
- { "a",
- "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb\x24" },
- { "abc",
- "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d" },
- { "message digest",
- "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01\x4b" },
- { "abcdefghijklmnopqrstuvwxyz",
- "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d\xa9" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4" },
- { "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
- "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05\x36" }
- };
+ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+ "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05\x36"
+ }
+};
static void
report_failure(int n, const char *tag,
diff --git a/test-alg-md5.c b/test-alg-md5.c
index 579c843..c267cb9 100644
--- a/test-alg-md5.c
+++ b/test-alg-md5.c
@@ -9,29 +9,45 @@ static const struct
const char *input;
const char result[16];
} tests[] =
+{
+ /* "Informal" test vectors from
+ https://www.nist.gov/itl/ssd/software-quality-group/nsrl-test-data
+ (these were once in FIPS 180-2, but MD5 has been withdrawn). */
+ {
+ "abc",
+ "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72"
+ },
+ {
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "\x82\x15\xef\x07\x96\xa2\x0b\xca\xaa\xe1\x16\xd3\x87\x6c\x66\x4a"
+ },
+ /* Test vectors from the NESSIE project. */
+ {
+ "",
+ "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e"
+ },
+ {
+ "a",
+ "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61"
+ },
+ {
+ "message digest",
+ "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0"
+ },
+ {
+ "abcdefghijklmnopqrstuvwxyz",
+ "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"
+ },
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f"
+ },
{
- /* "Informal" test vectors from
- https://www.nist.gov/itl/ssd/software-quality-group/nsrl-test-data
- (these were once in FIPS 180-2, but MD5 has been withdrawn). */
- { "abc",
- "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72" },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "\x82\x15\xef\x07\x96\xa2\x0b\xca\xaa\xe1\x16\xd3\x87\x6c\x66\x4a" },
- /* Test vectors from the NESSIE project. */
- { "",
- "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e" },
- { "a",
- "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61" },
- { "message digest",
- "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0" },
- { "abcdefghijklmnopqrstuvwxyz",
- "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f" },
- { "123456789012345678901234567890123456789012345678901234567890"
- "12345678901234567890",
- "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6\x7a" }
- };
+ "123456789012345678901234567890123456789012345678901234567890"
+ "12345678901234567890",
+ "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6\x7a"
+ }
+};
static void
report_failure(int n, const char *tag,
diff --git a/test-alg-sha256.c b/test-alg-sha256.c
index 8ade993..d219676 100644
--- a/test-alg-sha256.c
+++ b/test-alg-sha256.c
@@ -9,36 +9,52 @@ static const struct
const char *input;
const char result[32];
} tests[] =
+{
+ /* Test vectors from FIPS 180-2: appendix B.1. */
+ {
+ "abc",
+ "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23"
+ "\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad"
+ },
+ /* Test vectors from FIPS 180-2: appendix B.2. */
+ {
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
+ "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1"
+ },
+ /* Test vectors from the NESSIE project. */
+ {
+ "",
+ "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
+ "\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55"
+ },
+ {
+ "a",
+ "\xca\x97\x81\x12\xca\x1b\xbd\xca\xfa\xc2\x31\xb3\x9a\x23\xdc\x4d"
+ "\xa7\x86\xef\xf8\x14\x7c\x4e\x72\xb9\x80\x77\x85\xaf\xee\x48\xbb"
+ },
+ {
+ "message digest",
+ "\xf7\x84\x6f\x55\xcf\x23\xe1\x4e\xeb\xea\xb5\xb4\xe1\x55\x0c\xad"
+ "\x5b\x50\x9e\x33\x48\xfb\xc4\xef\xa3\xa1\x41\x3d\x39\x3c\xb6\x50"
+ },
+ {
+ "abcdefghijklmnopqrstuvwxyz",
+ "\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52"
+ "\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73"
+ },
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "\xdb\x4b\xfc\xbd\x4d\xa0\xcd\x85\xa6\x0c\x3c\x37\xd3\xfb\xd8\x80"
+ "\x5c\x77\xf1\x5f\xc6\xb1\xfd\xfe\x61\x4e\xe0\xa7\xc8\xfd\xb4\xc0"
+ },
{
- /* Test vectors from FIPS 180-2: appendix B.1. */
- { "abc",
- "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23"
- "\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad" },
- /* Test vectors from FIPS 180-2: appendix B.2. */
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
- "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" },
- /* Test vectors from the NESSIE project. */
- { "",
- "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
- "\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55" },
- { "a",
- "\xca\x97\x81\x12\xca\x1b\xbd\xca\xfa\xc2\x31\xb3\x9a\x23\xdc\x4d"
- "\xa7\x86\xef\xf8\x14\x7c\x4e\x72\xb9\x80\x77\x85\xaf\xee\x48\xbb" },
- { "message digest",
- "\xf7\x84\x6f\x55\xcf\x23\xe1\x4e\xeb\xea\xb5\xb4\xe1\x55\x0c\xad"
- "\x5b\x50\x9e\x33\x48\xfb\xc4\xef\xa3\xa1\x41\x3d\x39\x3c\xb6\x50" },
- { "abcdefghijklmnopqrstuvwxyz",
- "\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52"
- "\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "\xdb\x4b\xfc\xbd\x4d\xa0\xcd\x85\xa6\x0c\x3c\x37\xd3\xfb\xd8\x80"
- "\x5c\x77\xf1\x5f\xc6\xb1\xfd\xfe\x61\x4e\xe0\xa7\xc8\xfd\xb4\xc0" },
- { "123456789012345678901234567890123456789012345678901234567890"
- "12345678901234567890",
- "\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e"
- "\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e" }
- };
+ "123456789012345678901234567890123456789012345678901234567890"
+ "12345678901234567890",
+ "\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e"
+ "\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e"
+ }
+};
static void
@@ -77,7 +93,7 @@ main (void)
{
sha256_init_ctx (&ctx);
sha256_process_bytes (tests[cnt].input, strlen (tests[cnt].input),
- &ctx);
+ &ctx);
sha256_finish_ctx (&ctx, sum);
if (memcmp (tests[cnt].result, sum, 32) != 0)
{
diff --git a/test-alg-sha512.c b/test-alg-sha512.c
index eb08253..074bdf0 100644
--- a/test-alg-sha512.c
+++ b/test-alg-sha512.c
@@ -9,58 +9,76 @@ static const struct
const char *input;
const char result[64];
} tests[] =
+{
+ /* Test vectors from FIPS 180-2: appendix C.1. */
+ {
+ "abc",
+ "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31"
+ "\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a"
+ "\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd"
+ "\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f"
+ },
+ /* Test vectors from FIPS 180-2: appendix C.2. */
+ {
+ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
+ "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+ "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f"
+ "\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18"
+ "\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a"
+ "\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09"
+ },
+ /* Test vectors from the NESSIE project. */
+ {
+ "",
+ "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80\x07"
+ "\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c\xe9\xce"
+ "\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87\x7e\xec\x2f"
+ "\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a\xf9\x27\xda\x3e"
+ },
+ {
+ "a",
+ "\x1f\x40\xfc\x92\xda\x24\x16\x94\x75\x09\x79\xee\x6c\xf5\x82\xf2"
+ "\xd5\xd7\xd2\x8e\x18\x33\x5d\xe0\x5a\xbc\x54\xd0\x56\x0e\x0f\x53"
+ "\x02\x86\x0c\x65\x2b\xf0\x8d\x56\x02\x52\xaa\x5e\x74\x21\x05\x46"
+ "\xf3\x69\xfb\xbb\xce\x8c\x12\xcf\xc7\x95\x7b\x26\x52\xfe\x9a\x75"
+ },
+ {
+ "message digest",
+ "\x10\x7d\xbf\x38\x9d\x9e\x9f\x71\xa3\xa9\x5f\x6c\x05\x5b\x92\x51"
+ "\xbc\x52\x68\xc2\xbe\x16\xd6\xc1\x34\x92\xea\x45\xb0\x19\x9f\x33"
+ "\x09\xe1\x64\x55\xab\x1e\x96\x11\x8e\x8a\x90\x5d\x55\x97\xb7\x20"
+ "\x38\xdd\xb3\x72\xa8\x98\x26\x04\x6d\xe6\x66\x87\xbb\x42\x0e\x7c"
+ },
+ {
+ "abcdefghijklmnopqrstuvwxyz",
+ "\x4d\xbf\xf8\x6c\xc2\xca\x1b\xae\x1e\x16\x46\x8a\x05\xcb\x98\x81"
+ "\xc9\x7f\x17\x53\xbc\xe3\x61\x90\x34\x89\x8f\xaa\x1a\xab\xe4\x29"
+ "\x95\x5a\x1b\xf8\xec\x48\x3d\x74\x21\xfe\x3c\x16\x46\x61\x3a\x59"
+ "\xed\x54\x41\xfb\x0f\x32\x13\x89\xf7\x7f\x48\xa8\x79\xc7\xb1\xf1"
+ },
+ {
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "\x20\x4a\x8f\xc6\xdd\xa8\x2f\x0a\x0c\xed\x7b\xeb\x8e\x08\xa4\x16"
+ "\x57\xc1\x6e\xf4\x68\xb2\x28\xa8\x27\x9b\xe3\x31\xa7\x03\xc3\x35"
+ "\x96\xfd\x15\xc1\x3b\x1b\x07\xf9\xaa\x1d\x3b\xea\x57\x78\x9c\xa0"
+ "\x31\xad\x85\xc7\xa7\x1d\xd7\x03\x54\xec\x63\x12\x38\xca\x34\x45"
+ },
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "\x1e\x07\xbe\x23\xc2\x6a\x86\xea\x37\xea\x81\x0c\x8e\xc7\x80\x93"
+ "\x52\x51\x5a\x97\x0e\x92\x53\xc2\x6f\x53\x6c\xfc\x7a\x99\x96\xc4"
+ "\x5c\x83\x70\x58\x3e\x0a\x78\xfa\x4a\x90\x04\x1d\x71\xa4\xce\xab"
+ "\x74\x23\xf1\x9c\x71\xb9\xd5\xa3\xe0\x12\x49\xf0\xbe\xbd\x58\x94"
+ },
{
- /* Test vectors from FIPS 180-2: appendix C.1. */
- { "abc",
- "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31"
- "\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a"
- "\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd"
- "\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f" },
- /* Test vectors from FIPS 180-2: appendix C.2. */
- { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
- "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
- "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f"
- "\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18"
- "\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a"
- "\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09" },
- /* Test vectors from the NESSIE project. */
- { "",
- "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80\x07"
- "\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c\xe9\xce"
- "\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87\x7e\xec\x2f"
- "\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a\xf9\x27\xda\x3e" },
- { "a",
- "\x1f\x40\xfc\x92\xda\x24\x16\x94\x75\x09\x79\xee\x6c\xf5\x82\xf2"
- "\xd5\xd7\xd2\x8e\x18\x33\x5d\xe0\x5a\xbc\x54\xd0\x56\x0e\x0f\x53"
- "\x02\x86\x0c\x65\x2b\xf0\x8d\x56\x02\x52\xaa\x5e\x74\x21\x05\x46"
- "\xf3\x69\xfb\xbb\xce\x8c\x12\xcf\xc7\x95\x7b\x26\x52\xfe\x9a\x75" },
- { "message digest",
- "\x10\x7d\xbf\x38\x9d\x9e\x9f\x71\xa3\xa9\x5f\x6c\x05\x5b\x92\x51"
- "\xbc\x52\x68\xc2\xbe\x16\xd6\xc1\x34\x92\xea\x45\xb0\x19\x9f\x33"
- "\x09\xe1\x64\x55\xab\x1e\x96\x11\x8e\x8a\x90\x5d\x55\x97\xb7\x20"
- "\x38\xdd\xb3\x72\xa8\x98\x26\x04\x6d\xe6\x66\x87\xbb\x42\x0e\x7c" },
- { "abcdefghijklmnopqrstuvwxyz",
- "\x4d\xbf\xf8\x6c\xc2\xca\x1b\xae\x1e\x16\x46\x8a\x05\xcb\x98\x81"
- "\xc9\x7f\x17\x53\xbc\xe3\x61\x90\x34\x89\x8f\xaa\x1a\xab\xe4\x29"
- "\x95\x5a\x1b\xf8\xec\x48\x3d\x74\x21\xfe\x3c\x16\x46\x61\x3a\x59"
- "\xed\x54\x41\xfb\x0f\x32\x13\x89\xf7\x7f\x48\xa8\x79\xc7\xb1\xf1" },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "\x20\x4a\x8f\xc6\xdd\xa8\x2f\x0a\x0c\xed\x7b\xeb\x8e\x08\xa4\x16"
- "\x57\xc1\x6e\xf4\x68\xb2\x28\xa8\x27\x9b\xe3\x31\xa7\x03\xc3\x35"
- "\x96\xfd\x15\xc1\x3b\x1b\x07\xf9\xaa\x1d\x3b\xea\x57\x78\x9c\xa0"
- "\x31\xad\x85\xc7\xa7\x1d\xd7\x03\x54\xec\x63\x12\x38\xca\x34\x45" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "\x1e\x07\xbe\x23\xc2\x6a\x86\xea\x37\xea\x81\x0c\x8e\xc7\x80\x93"
- "\x52\x51\x5a\x97\x0e\x92\x53\xc2\x6f\x53\x6c\xfc\x7a\x99\x96\xc4"
- "\x5c\x83\x70\x58\x3e\x0a\x78\xfa\x4a\x90\x04\x1d\x71\xa4\xce\xab"
- "\x74\x23\xf1\x9c\x71\xb9\xd5\xa3\xe0\x12\x49\xf0\xbe\xbd\x58\x94" },
- { "123456789012345678901234567890123456789012345678901234567890"
- "12345678901234567890",
- "\x72\xec\x1e\xf1\x12\x4a\x45\xb0\x47\xe8\xb7\xc7\x5a\x93\x21\x95"
- "\x13\x5b\xb6\x1d\xe2\x4e\xc0\xd1\x91\x40\x42\x24\x6e\x0a\xec\x3a"
- "\x23\x54\xe0\x93\xd7\x6f\x30\x48\xb4\x56\x76\x43\x46\x90\x0c\xb1"
- "\x30\xd2\xa4\xfd\x5d\xd1\x6a\xbb\x5e\x30\xbc\xb8\x50\xde\xe8\x43" }
- };
+ "123456789012345678901234567890123456789012345678901234567890"
+ "12345678901234567890",
+ "\x72\xec\x1e\xf1\x12\x4a\x45\xb0\x47\xe8\xb7\xc7\x5a\x93\x21\x95"
+ "\x13\x5b\xb6\x1d\xe2\x4e\xc0\xd1\x91\x40\x42\x24\x6e\x0a\xec\x3a"
+ "\x23\x54\xe0\x93\xd7\x6f\x30\x48\xb4\x56\x76\x43\x46\x90\x0c\xb1"
+ "\x30\xd2\xa4\xfd\x5d\xd1\x6a\xbb\x5e\x30\xbc\xb8\x50\xde\xe8\x43"
+ }
+};
static void
@@ -103,7 +121,7 @@ main (void)
{
sha512_init_ctx (&ctx);
sha512_process_bytes (tests[cnt].input, strlen (tests[cnt].input),
- &ctx);
+ &ctx);
sha512_finish_ctx (&ctx, sum);
if (memcmp (tests[cnt].result, sum, 64) != 0)
{
diff --git a/test-byteorder.c b/test-byteorder.c
index 000b8bd..33a6bf4 100644
--- a/test-byteorder.c
+++ b/test-byteorder.c
@@ -38,7 +38,8 @@ struct test_64
static int
test_le32 (void)
{
- static const struct test_32 cases[] = {
+ static const struct test_32 cases[] =
+ {
{ 0x00000000, "\x00\x00\x00\x00" },
{ 0xFF000000, "\x00\x00\x00\xFF" },
{ 0x00FF0000, "\x00\x00\xFF\x00" },
@@ -84,7 +85,8 @@ test_le32 (void)
static int
test_be32 (void)
{
- static const struct test_32 cases[] = {
+ static const struct test_32 cases[] =
+ {
{ 0x00000000, "\x00\x00\x00\x00" },
{ 0xFF000000, "\xFF\x00\x00\x00" },
{ 0x00FF0000, "\x00\xFF\x00\x00" },
@@ -130,7 +132,8 @@ test_be32 (void)
static int
test_le64 (void)
{
- static const struct test_64 cases[] = {
+ static const struct test_64 cases[] =
+ {
{ 0x0000000000000000ull, "\x00\x00\x00\x00\x00\x00\x00\x00" },
{ 0x00000000000000FFull, "\xFF\x00\x00\x00\x00\x00\x00\x00" },
{ 0x000000000000FF00ull, "\x00\xFF\x00\x00\x00\x00\x00\x00" },
@@ -186,7 +189,8 @@ test_le64 (void)
static int
test_be64 (void)
{
- static const struct test_64 cases[] = {
+ static const struct test_64 cases[] =
+ {
{ 0x0000000000000000ull, "\x00\x00\x00\x00\x00\x00\x00\x00" },
{ 0x00000000000000FFull, "\x00\x00\x00\x00\x00\x00\x00\xFF" },
{ 0x000000000000FF00ull, "\x00\x00\x00\x00\x00\x00\xFF\x00" },
diff --git a/test-crypt-badsalt.c b/test-crypt-badsalt.c
index 336ac3d..12892ba 100644
--- a/test-crypt-badsalt.c
+++ b/test-crypt-badsalt.c
@@ -23,19 +23,19 @@
#include <crypt.h>
static const char *tests[][3] =
- {
- { "no salt", "", "..ogcgXxFhnjI" /* valid setting */ },
- { "single char", "/", "*0" /* invalid setting */ },
- { "first char bad", "!x", "*0" /* invalid setting */ },
- { "second char bad", "Z%", "*0" /* invalid setting */ },
- { "both chars bad", ":@", "*0" /* invalid setting */ },
- { "un$upported algorithm", "$2$", "*0" /* invalid setting */ },
- { "un$upported $etting", "$2a$", "*0" /* invalid setting */ },
- { "un$upported $etting", "$2b$", "*0" /* invalid setting */ },
- { "un$upported $etting", "$2x$", "*0" /* invalid setting */ },
- { "bad salt for BSDi", "_1", "*0" /* invalid setting */ },
- { "end of page", NULL, "*0" /* invalid setting */ }
- };
+{
+ { "no salt", "", "..ogcgXxFhnjI" /* valid setting */ },
+ { "single char", "/", "*0" /* invalid setting */ },
+ { "first char bad", "!x", "*0" /* invalid setting */ },
+ { "second char bad", "Z%", "*0" /* invalid setting */ },
+ { "both chars bad", ":@", "*0" /* invalid setting */ },
+ { "un$upported algorithm", "$2$", "*0" /* invalid setting */ },
+ { "un$upported $etting", "$2a$", "*0" /* invalid setting */ },
+ { "un$upported $etting", "$2b$", "*0" /* invalid setting */ },
+ { "un$upported $etting", "$2x$", "*0" /* invalid setting */ },
+ { "bad salt for BSDi", "_1", "*0" /* invalid setting */ },
+ { "end of page", NULL, "*0" /* invalid setting */ }
+};
int
main (void)
@@ -52,7 +52,7 @@ main (void)
/* Check that crypt won't look at the second character if the first
one is invalid. */
page = mmap (NULL, pagesize * 2, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON, -1, 0);
+ MAP_PRIVATE | MAP_ANON, -1, 0);
if (page == MAP_FAILED)
{
perror ("mmap");
@@ -61,9 +61,9 @@ main (void)
else
{
if (mmap (page + pagesize, pagesize, 0,
- MAP_PRIVATE | MAP_ANON | MAP_FIXED,
- -1, 0) != page + pagesize)
- perror ("mmap 2");
+ MAP_PRIVATE | MAP_ANON | MAP_FIXED,
+ -1, 0) != page + pagesize)
+ perror ("mmap 2");
page[pagesize - 1] = special[0];
tests[n - 1][1] = &page[pagesize - 1];
}
@@ -72,8 +72,8 @@ main (void)
{
retval = crypt (tests[i][0], tests[i][1]);
if (strcmp (tests[i][2], retval))
- {
- result++;
+ {
+ result++;
if (memcmp (&page[pagesize - 1], tests[i][1], 1) != 0)
saltstr = tests[i][1];
else
@@ -82,12 +82,12 @@ main (void)
tests[i][0], saltstr);
printf (" expected: \"%s\"\n got: \"%s\"\n\n",
tests[i][2], retval);
- }
+ }
retval = crypt_r (tests[i][0], tests[i][1], &cd);
if (strcmp (tests[i][2], retval))
- {
- result++;
+ {
+ result++;
if (memcmp (&page[pagesize - 1], tests[i][1], 1) != 0)
saltstr = tests[i][1];
else
@@ -96,13 +96,13 @@ main (void)
tests[i][0], saltstr);
printf (" expected: \"%s\"\n got: \"%s\"\n\n",
tests[i][2], retval);
- }
+ }
crypt_rn (tests[i][0], tests[i][1], cdptr, cdsize);
retval = cd.output;
if (strcmp (tests[i][2], retval))
- {
- result++;
+ {
+ result++;
if (memcmp (&page[pagesize - 1], tests[i][1], 1) != 0)
saltstr = tests[i][1];
else
@@ -111,13 +111,13 @@ main (void)
tests[i][0], saltstr);
printf (" expected: \"%s\"\n got: \"%s\"\n\n",
tests[i][2], retval);
- }
+ }
crypt_ra (tests[i][0], tests[i][1], (void **)&cdptr, &cdsize);
retval = cd.output;
if (strcmp (tests[i][2], retval))
- {
- result++;
+ {
+ result++;
if (memcmp (&page[pagesize - 1], tests[i][1], 1) != 0)
saltstr = tests[i][1];
else
@@ -126,7 +126,7 @@ main (void)
tests[i][0], saltstr);
printf (" expected: \"%s\"\n got: \"%s\"\n\n",
tests[i][2], retval);
- }
+ }
}
return result;
diff --git a/test-crypt-bcrypt.c b/test-crypt-bcrypt.c
index e8ccdfd..ddd9296 100644
--- a/test-crypt-bcrypt.c
+++ b/test-crypt-bcrypt.c
@@ -22,81 +22,138 @@
#include <stdlib.h>
#include <string.h>
-static const char *tests[][3] = {
- { "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW",
- "U*U" },
- { "$2a$05$CCCCCCCCCCCCCCCCCCCCC.VGOzA784oUp/Z0DY336zx7pLYAy0lwK",
- "U*U*" },
- { "$2a$05$XXXXXXXXXXXXXXXXXXXXXOAcXxm9kjPGEMsLznoKqmqw7tc8WCx4a",
- "U*U*U" },
- { "$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui",
+static const char *tests[][3] =
+{
+ {
+ "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW",
+ "U*U"
+ },
+ {
+ "$2a$05$CCCCCCCCCCCCCCCCCCCCC.VGOzA784oUp/Z0DY336zx7pLYAy0lwK",
+ "U*U*"
+ },
+ {
+ "$2a$05$XXXXXXXXXXXXXXXXXXXXXOAcXxm9kjPGEMsLznoKqmqw7tc8WCx4a",
+ "U*U*U"
+ },
+ {
+ "$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui",
"0123456789abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
- "chars after 72 are ignored" },
- { "$2x$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
- "\xa3" },
- { "$2x$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
- "\xff\xff\xa3" },
- { "$2y$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
- "\xff\xff\xa3" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.nqd1wy.pTMdcvrRWxyiGL2eMz.2a85.",
- "\xff\xff\xa3" },
- { "$2b$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
- "\xff\xff\xa3" },
- { "$2y$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq",
- "\xa3" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq",
- "\xa3" },
- { "$2b$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq",
- "\xa3" },
- { "$2x$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
- "1\xa3" "345" },
- { "$2x$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
- "\xff\xa3" "345" },
- { "$2x$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
- "\xff\xa3" "34" "\xff\xff\xff\xa3" "345" },
- { "$2y$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
- "\xff\xa3" "34" "\xff\xff\xff\xa3" "345" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.ZC1JEJ8Z4gPfpe1JOr/oyPXTWl9EFd.",
- "\xff\xa3" "34" "\xff\xff\xff\xa3" "345" },
- { "$2y$05$/OK.fbVrR/bpIqNJ5ianF.nRht2l/HRhr6zmCp9vYUvvsqynflf9e",
- "\xff\xa3" "345" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.nRht2l/HRhr6zmCp9vYUvvsqynflf9e",
- "\xff\xa3" "345" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.6IflQkJytoRVc1yuaNtHfiuq.FRlSIS",
- "\xa3" "ab" },
- { "$2x$05$/OK.fbVrR/bpIqNJ5ianF.6IflQkJytoRVc1yuaNtHfiuq.FRlSIS",
- "\xa3" "ab" },
- { "$2y$05$/OK.fbVrR/bpIqNJ5ianF.6IflQkJytoRVc1yuaNtHfiuq.FRlSIS",
- "\xa3" "ab" },
- { "$2x$05$6bNw2HLQYeqHYyBfLMsv/OiwqTymGIGzFsA4hOTWebfehXHNprcAS",
- "\xd1\x91" },
- { "$2x$05$6bNw2HLQYeqHYyBfLMsv/O9LIGgn8OMzuDoHfof8AQimSGfcSWxnS",
- "\xd0\xc1\xd2\xcf\xcc\xd8" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.swQOIzjOiJ9GHEPuhEkvqrUyvWhEMx6",
+ "chars after 72 are ignored"
+ },
+ {
+ "$2x$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
+ "\xa3"
+ },
+ {
+ "$2x$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
+ "\xff\xff\xa3"
+ },
+ {
+ "$2y$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
+ "\xff\xff\xa3"
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.nqd1wy.pTMdcvrRWxyiGL2eMz.2a85.",
+ "\xff\xff\xa3"
+ },
+ {
+ "$2b$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e",
+ "\xff\xff\xa3"
+ },
+ {
+ "$2y$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq",
+ "\xa3"
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq",
+ "\xa3"
+ },
+ {
+ "$2b$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq",
+ "\xa3"
+ },
+ {
+ "$2x$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
+ "1\xa3" "345"
+ },
+ {
+ "$2x$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
+ "\xff\xa3" "345"
+ },
+ {
+ "$2x$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
+ "\xff\xa3" "34" "\xff\xff\xff\xa3" "345"
+ },
+ {
+ "$2y$05$/OK.fbVrR/bpIqNJ5ianF.o./n25XVfn6oAPaUvHe.Csk4zRfsYPi",
+ "\xff\xa3" "34" "\xff\xff\xff\xa3" "345"
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.ZC1JEJ8Z4gPfpe1JOr/oyPXTWl9EFd.",
+ "\xff\xa3" "34" "\xff\xff\xff\xa3" "345"
+ },
+ {
+ "$2y$05$/OK.fbVrR/bpIqNJ5ianF.nRht2l/HRhr6zmCp9vYUvvsqynflf9e",
+ "\xff\xa3" "345"
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.nRht2l/HRhr6zmCp9vYUvvsqynflf9e",
+ "\xff\xa3" "345"
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.6IflQkJytoRVc1yuaNtHfiuq.FRlSIS",
+ "\xa3" "ab"
+ },
+ {
+ "$2x$05$/OK.fbVrR/bpIqNJ5ianF.6IflQkJytoRVc1yuaNtHfiuq.FRlSIS",
+ "\xa3" "ab"
+ },
+ {
+ "$2y$05$/OK.fbVrR/bpIqNJ5ianF.6IflQkJytoRVc1yuaNtHfiuq.FRlSIS",
+ "\xa3" "ab"
+ },
+ {
+ "$2x$05$6bNw2HLQYeqHYyBfLMsv/OiwqTymGIGzFsA4hOTWebfehXHNprcAS",
+ "\xd1\x91"
+ },
+ {
+ "$2x$05$6bNw2HLQYeqHYyBfLMsv/O9LIGgn8OMzuDoHfof8AQimSGfcSWxnS",
+ "\xd0\xc1\xd2\xcf\xcc\xd8"
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.swQOIzjOiJ9GHEPuhEkvqrUyvWhEMx6",
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
- "chars after 72 are ignored as usual" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.R9xrDjiycxMbQE2bp.vgqlYpW5wx2yy",
+ "chars after 72 are ignored as usual"
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.R9xrDjiycxMbQE2bp.vgqlYpW5wx2yy",
+ "\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55"
"\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55"
"\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55"
"\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55"
"\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55"
"\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55"
- "\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55" },
- { "$2a$05$/OK.fbVrR/bpIqNJ5ianF.9tQZzcJfm3uj2NvJ/n5xkhpqLrMpWCe",
+ },
+ {
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.9tQZzcJfm3uj2NvJ/n5xkhpqLrMpWCe",
+ "\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff"
"\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff"
"\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff"
"\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff"
"\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff"
"\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff"
- "\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff" },
- { "$2a$05$CCCCCCCCCCCCCCCCCCCCC.7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy",
- "" },
+ },
+ {
+ "$2a$05$CCCCCCCCCCCCCCCCCCCCC.7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy",
+ ""
+ },
{ "*0", "", "$2a$03$CCCCCCCCCCCCCCCCCCCCC." },
{ "*0", "", "$2a$32$CCCCCCCCCCCCCCCCCCCCC." },
{ "*0", "", "$2c$05$CCCCCCCCCCCCCCCCCCCCC." },
diff --git a/test-crypt-des.c b/test-crypt-des.c
index 58c0821..1e2e348 100644
--- a/test-crypt-des.c
+++ b/test-crypt-des.c
@@ -29,8 +29,10 @@ static const struct
{ "_J9..XXXX", "_J9..XXXXsqM/YSSP..Y", "*U*U*U*U*" },
{ "_J9..XXXX", "_J9..XXXXVL7qJCnku0I", "*U*U*U*U*U*U*U*U" },
{ "_J9..XXXX", "_J9..XXXXAj8cFbP5scI", "*U*U*U*U*U*U*U*U*" },
- { "_J9..XXXX", "_J9..XXXXAj8cFbP5scI", "\xaa\xd5\xaa\xd5\xaa\xd5\xaa\xd5\xaa"
- "\xd5\xaa\xd5\xaa\xd5\xaa\xd5\xaa" },
+ {
+ "_J9..XXXX", "_J9..XXXXAj8cFbP5scI", "\xaa\xd5\xaa\xd5\xaa\xd5\xaa\xd5\xaa"
+ "\xd5\xaa\xd5\xaa\xd5\xaa\xd5\xaa"
+ },
{ "_J9..SDiz", "_J9..SDizh.vll5VED9g", "ab1234567" },
{ "_J9..SDiz", "_J9..SDizRjWQ/zePPHc", "cr1234567" },
{ "_J9..SDiz", "_J9..SDizxmRI1GjnQuE", "zxyDPWgydbQjgq" },
@@ -54,10 +56,14 @@ static const struct
{ "Xh..............", "XhWbBsxo8cYpYvYwQItwv0qc", "challenge" },
/* bigcrypt still discards the 8th bit of every character. */
- { "Cx..............", "CxcR5MY6TS58EVRba0DA/cW.",
- "\xe1\xec\xe5\xf8\xe1\xee\xe4\xe5\xf2" /* alexander */ },
- { "6M..............", "6MvZdspyAL4QEId8ugLUEeDs",
- "\xf3\xf4\xe5\xf0\xe8\xe1\xee\xe9\xe5" /* stephanie */ },
+ {
+ "Cx..............", "CxcR5MY6TS58EVRba0DA/cW.",
+ "\xe1\xec\xe5\xf8\xe1\xee\xe4\xe5\xf2" /* alexander */
+ },
+ {
+ "6M..............", "6MvZdspyAL4QEId8ugLUEeDs",
+ "\xf3\xf4\xe5\xf0\xe8\xe1\xee\xe9\xe5" /* stephanie */
+ },
};
#define ntests (sizeof (tests) / sizeof (tests[0]))
diff --git a/test-crypt-nonnull.c b/test-crypt-nonnull.c
index c76360d..27313f0 100644
--- a/test-crypt-nonnull.c
+++ b/test-crypt-nonnull.c
@@ -23,18 +23,18 @@
#include <crypt.h>
static const char *tests[][3] =
- {
- { "single char", "/" },
- { "first char bad", "!x" },
- { "second char bad", "Z%" },
- { "both chars bad", ":@" },
- { "un$upported algorithm", "$2$" },
- { "un$upported $etting", "$2a$" },
- { "un$upported $etting", "$2b$" },
- { "un$upported $etting", "$2x$" },
- { "bad salt for BSDi", "_1" },
- { "end of page", NULL }
- };
+{
+ { "single char", "/" },
+ { "first char bad", "!x" },
+ { "second char bad", "Z%" },
+ { "both chars bad", ":@" },
+ { "un$upported algorithm", "$2$" },
+ { "un$upported $etting", "$2a$" },
+ { "un$upported $etting", "$2b$" },
+ { "un$upported $etting", "$2x$" },
+ { "bad salt for BSDi", "_1" },
+ { "end of page", NULL }
+};
int
main (void)
@@ -51,7 +51,7 @@ main (void)
/* Check that crypt won't look at the second character if the first
one is invalid. */
page = mmap (NULL, pagesize * 2, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON, -1, 0);
+ MAP_PRIVATE | MAP_ANON, -1, 0);
if (page == MAP_FAILED)
{
perror ("mmap");
@@ -60,9 +60,9 @@ main (void)
else
{
if (mmap (page + pagesize, pagesize, 0,
- MAP_PRIVATE | MAP_ANON | MAP_FIXED,
- -1, 0) != page + pagesize)
- perror ("mmap 2");
+ MAP_PRIVATE | MAP_ANON | MAP_FIXED,
+ -1, 0) != page + pagesize)
+ perror ("mmap 2");
page[pagesize - 1] = special[0];
tests[n - 1][1] = &page[pagesize - 1];
}
@@ -70,26 +70,26 @@ main (void)
for (size_t i = 0; i < n; i++)
{
if (crypt_rn (tests[i][0], tests[i][1], cdptr, cdsize))
- {
- result++;
+ {
+ result++;
if (memcmp (&page[pagesize - 1], tests[i][1], 1) != 0)
saltstr = tests[i][1];
else
saltstr = special;
printf ("%s: crypt_rn returned non-NULL with salt \"%s\"\n",
tests[i][0], saltstr);
- }
+ }
if (crypt_ra (tests[i][0], tests[i][1], (void **)&cdptr, &cdsize))
- {
- result++;
+ {
+ result++;
if (memcmp (&page[pagesize - 1], tests[i][1], 1) != 0)
saltstr = tests[i][1];
else
saltstr = special;
printf ("%s: crypt_ra returned non-NULL with salt \"%s\"\n",
tests[i][0], saltstr);
- }
+ }
}
return result;
diff --git a/test-crypt-nthash.c b/test-crypt-nthash.c
index 60fda12..a23d878 100644
--- a/test-crypt-nthash.c
+++ b/test-crypt-nthash.c
@@ -23,54 +23,102 @@ static const struct
As shown on:
http://openwall.info/wiki/john/Generating-test-hashes#NT-hash */
- { "",
- "$3$$31d6cfe0d16ae931b73c59d7e0c089c0" },
- { " ",
- "$3$$71c5391067de41fad6f3063162e5eeff" },
- { "multiple words seperated by spaces",
- "$3$$51439a927ed19fe271002bb43f355758" },
- { "multiple word$ $eperated by $pace$ and $pecial character$",
- "$3$$48370cb663dfc4a0a54555764653c7f3" },
- { ".....",
- "$3$$c68e5da4d65da3c0af82c12b570a70db" },
- { "a",
- "$3$$186cb09181e2c2ecaac768c47c729904" },
- { "abc",
- "$3$$e0fba38268d0ec66ef1cb452d5885e53" },
- { "abcdefghijklmnopqrstuvwxyz",
- "$3$$0bd63185f3484bb000286c85917dc12e" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "$3$$2e74cc46c96ee4caee5df20d0898fef8" },
- { "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
- "$3$$cf17b1ae2606afa964193690df7543b1" },
- { "|_337T`/p3",
- "$3$$ca8ad8058c3226764a3af34a8edcbb2e" },
- { "photojournalism",
- "$3$$83200a50482a6daf45b2902ed52042f2" },
- { "ecclesiastically",
- "$3$$0b83b68ba7a5ce58ed50bb0f9a5fa06a" },
- { "congregationalism",
- "$3$$ebd2b24e1ee857784f6ac40fd500077e" },
- { "dihydrosphingosine",
- "$3$$40fabb09b52fb8a7843f7e1ee723cf03" },
- { "semianthropological",
- "$3$$1eba95138c99f9a0621d24876eea2868" },
- { "palaeogeographically",
- "$3$$5d6536aea6febd7b98e373cfd3f28a85" },
- { "electromyographically",
- "$3$$a27af10e890b5e0856360a4d993eeb77" },
- { "noninterchangeableness",
- "$3$$3f820d837c34f4019203f9ae5df458e7" },
- { "electroencephalographically",
- "$3$$ed5d6deb9f1510c55d8c825c05985a42" },
- { "antidisestablishmentarianism",
- "$3$$bf4dd2e2566dfb4fafae5f7b0ef32470" },
- { "cyclotrimethylenetrinitramine",
- "$3$$260a9c487c4815769245a28c242ed260" },
- { "dichlorodiphenyltrichloroethane",
- "$3$$6674a3a9bb08c4e58b2cda57c66ea608" },
- { "supercalifragilisticexpialidocious",
- "$3$$f5295d5b0a47abecb70ed08bdb6d4e6e" }
+ {
+ "",
+ "$3$$31d6cfe0d16ae931b73c59d7e0c089c0"
+ },
+ {
+ " ",
+ "$3$$71c5391067de41fad6f3063162e5eeff"
+ },
+ {
+ "multiple words seperated by spaces",
+ "$3$$51439a927ed19fe271002bb43f355758"
+ },
+ {
+ "multiple word$ $eperated by $pace$ and $pecial character$",
+ "$3$$48370cb663dfc4a0a54555764653c7f3"
+ },
+ {
+ ".....",
+ "$3$$c68e5da4d65da3c0af82c12b570a70db"
+ },
+ {
+ "a",
+ "$3$$186cb09181e2c2ecaac768c47c729904"
+ },
+ {
+ "abc",
+ "$3$$e0fba38268d0ec66ef1cb452d5885e53"
+ },
+ {
+ "abcdefghijklmnopqrstuvwxyz",
+ "$3$$0bd63185f3484bb000286c85917dc12e"
+ },
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "$3$$2e74cc46c96ee4caee5df20d0898fef8"
+ },
+ {
+ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+ "$3$$cf17b1ae2606afa964193690df7543b1"
+ },
+ {
+ "|_337T`/p3",
+ "$3$$ca8ad8058c3226764a3af34a8edcbb2e"
+ },
+ {
+ "photojournalism",
+ "$3$$83200a50482a6daf45b2902ed52042f2"
+ },
+ {
+ "ecclesiastically",
+ "$3$$0b83b68ba7a5ce58ed50bb0f9a5fa06a"
+ },
+ {
+ "congregationalism",
+ "$3$$ebd2b24e1ee857784f6ac40fd500077e"
+ },
+ {
+ "dihydrosphingosine",
+ "$3$$40fabb09b52fb8a7843f7e1ee723cf03"
+ },
+ {
+ "semianthropological",
+ "$3$$1eba95138c99f9a0621d24876eea2868"
+ },
+ {
+ "palaeogeographically",
+ "$3$$5d6536aea6febd7b98e373cfd3f28a85"
+ },
+ {
+ "electromyographically",
+ "$3$$a27af10e890b5e0856360a4d993eeb77"
+ },
+ {
+ "noninterchangeableness",
+ "$3$$3f820d837c34f4019203f9ae5df458e7"
+ },
+ {
+ "electroencephalographically",
+ "$3$$ed5d6deb9f1510c55d8c825c05985a42"
+ },
+ {
+ "antidisestablishmentarianism",
+ "$3$$bf4dd2e2566dfb4fafae5f7b0ef32470"
+ },
+ {
+ "cyclotrimethylenetrinitramine",
+ "$3$$260a9c487c4815769245a28c242ed260"
+ },
+ {
+ "dichlorodiphenyltrichloroethane",
+ "$3$$6674a3a9bb08c4e58b2cda57c66ea608"
+ },
+ {
+ "supercalifragilisticexpialidocious",
+ "$3$$f5295d5b0a47abecb70ed08bdb6d4e6e"
+ }
};
#define ntests (sizeof (tests) / sizeof (tests[0]))
diff --git a/test-crypt-sha256.c b/test-crypt-sha256.c
index a5c2229..04be8b2 100644
--- a/test-crypt-sha256.c
+++ b/test-crypt-sha256.c
@@ -11,28 +11,42 @@ static const struct
const char *expected;
} tests[] =
{
- { "$5$saltstring", "Hello world!",
- "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5" },
- { "$5$rounds=10000$saltstringsaltstring", "Hello world!",
+ {
+ "$5$saltstring", "Hello world!",
+ "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5"
+ },
+ {
+ "$5$rounds=10000$saltstringsaltstring", "Hello world!",
"$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2."
- "opqey6IcA" },
- { "$5$rounds=5000$toolongsaltstring", "This is just a test",
+ "opqey6IcA"
+ },
+ {
+ "$5$rounds=5000$toolongsaltstring", "This is just a test",
"$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8"
- "mGRcvxa5" },
- { "$5$rounds=1400$anotherlongsaltstring",
+ "mGRcvxa5"
+ },
+ {
+ "$5$rounds=1400$anotherlongsaltstring",
"a very much longer text to encrypt. This one even stretches over more"
"than one line.",
"$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12"
- "oP84Bnq1" },
- { "$5$rounds=77777$short",
+ "oP84Bnq1"
+ },
+ {
+ "$5$rounds=77777$short",
"we have a short salt string but not a short password",
- "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/" },
- { "$5$rounds=123456$asaltof16chars..", "a short string",
+ "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/"
+ },
+ {
+ "$5$rounds=123456$asaltof16chars..", "a short string",
"$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/"
- "cZKmF/wJvD" },
- { "$5$rounds=10$roundstoolow", "the minimum number is still observed",
+ "cZKmF/wJvD"
+ },
+ {
+ "$5$rounds=10$roundstoolow", "the minimum number is still observed",
"$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97"
- "2bIC" },
+ "2bIC"
+ },
};
#define ntests (sizeof (tests) / sizeof (tests[0]))
diff --git a/test-crypt-sha512.c b/test-crypt-sha512.c
index 8376846..eae37a4 100644
--- a/test-crypt-sha512.c
+++ b/test-crypt-sha512.c
@@ -11,30 +11,44 @@ static const struct
const char *expected;
} tests[] =
{
- { "$6$saltstring", "Hello world!",
+ {
+ "$6$saltstring", "Hello world!",
"$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu"
- "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1" },
- { "$6$rounds=10000$saltstringsaltstring", "Hello world!",
+ "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1"
+ },
+ {
+ "$6$rounds=10000$saltstringsaltstring", "Hello world!",
"$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sb"
- "HbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v." },
- { "$6$rounds=5000$toolongsaltstring", "This is just a test",
+ "HbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v."
+ },
+ {
+ "$6$rounds=5000$toolongsaltstring", "This is just a test",
"$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQ"
- "zQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0" },
- { "$6$rounds=1400$anotherlongsaltstring",
+ "zQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0"
+ },
+ {
+ "$6$rounds=1400$anotherlongsaltstring",
"a very much longer text to encrypt. This one even stretches over more"
"than one line.",
"$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wP"
- "vMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1" },
- { "$6$rounds=77777$short",
+ "vMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1"
+ },
+ {
+ "$6$rounds=77777$short",
"we have a short salt string but not a short password",
"$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0g"
- "ge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0" },
- { "$6$rounds=123456$asaltof16chars..", "a short string",
+ "ge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0"
+ },
+ {
+ "$6$rounds=123456$asaltof16chars..", "a short string",
"$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwc"
- "elCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1" },
- { "$6$rounds=10$roundstoolow", "the minimum number is still observed",
+ "elCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1"
+ },
+ {
+ "$6$rounds=10$roundstoolow", "the minimum number is still observed",
"$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1x"
- "hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." },
+ "hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX."
+ },
};
#define ntests (sizeof (tests) / sizeof (tests[0]))
diff --git a/test-des-cases.h b/test-des-cases.h
index 50bef8b..03ca837 100644
--- a/test-des-cases.h
+++ b/test-des-cases.h
@@ -17,7 +17,8 @@ struct des_testcase
unsigned char answer[8];
};
-static const struct des_testcase des_testcases[] = {
+static const struct des_testcase des_testcases[] =
+{
{ "\x01\x01\x01\x01\x01\x01\x01\x01", "\x95\xf8\xa5\xe5\xdd\x31\xd9\x00", "\x80\x00\x00\x00\x00\x00\x00\x00" },
{ "\x01\x01\x01\x01\x01\x01\x01\x01", "\xdd\x7f\x12\x1c\xa5\x01\x56\x19", "\x40\x00\x00\x00\x00\x00\x00\x00" },
{ "\x01\x01\x01\x01\x01\x01\x01\x01", "\x2e\x86\x53\x10\x4f\x38\x34\xea", "\x20\x00\x00\x00\x00\x00\x00\x00" },
diff --git a/test-des-obsolete.c b/test-des-obsolete.c
index a643a27..65607a0 100644
--- a/test-des-obsolete.c
+++ b/test-des-obsolete.c
@@ -61,9 +61,9 @@ report_failure (size_t n, bool decrypt,
pk_print (tc->key);
fputs (" exp ", stdout);
if (decrypt)
- pk_print (tc->plain);
+ pk_print (tc->plain);
else
- pk_print (tc->answer);
+ pk_print (tc->answer);
fputs (" got ", stdout);
ex_print (got);
putchar ('\n');
diff --git a/test-des-obsolete_r.c b/test-des-obsolete_r.c
index 7bf3831..e6e77d6 100644
--- a/test-des-obsolete_r.c
+++ b/test-des-obsolete_r.c
@@ -61,9 +61,9 @@ report_failure (size_t n, bool decrypt,
pk_print (tc->key);
fputs (" exp ", stdout);
if (decrypt)
- pk_print (tc->plain);
+ pk_print (tc->plain);
else
- pk_print (tc->answer);
+ pk_print (tc->answer);
fputs (" got ", stdout);
ex_print (got);
putchar ('\n');
diff --git a/test-gensalt.c b/test-gensalt.c
index 6a9d4ed..9610d2c 100644
--- a/test-gensalt.c
+++ b/test-gensalt.c
@@ -6,7 +6,8 @@
#include <stdlib.h>
#include <string.h>
-static const char *const entropy[] = {
+static const char *const entropy[] =
+{
"\x58\x35\xcd\x26\x03\xab\x2c\x14\x92\x13\x1e\x59\xb0\xbc\xfe\xd5",
"\x9b\x35\xa2\x45\xeb\x68\x9e\x8f\xd9\xa9\x09\x71\xcc\x4d\x21\x44",
"\x25\x13\xc5\x94\xc3\x93\x1d\xf4\xfd\xd4\x4f\xbd\x10\xe5\x28\x08",
@@ -20,7 +21,8 @@ struct testcase
unsigned int expected_len;
};
-static const struct testcase testcases[] = {
+static const struct testcase testcases[] =
+{
#if ENABLE_WEAK_HASHES
{ "", 2 }, // DES
{ "_", 9 }, // BSDi extended DES