summaryrefslogtreecommitdiff
path: root/cipher
diff options
context:
space:
mode:
authorMoritz Schulte <mo@g10code.com>2003-06-09 13:50:37 +0000
committerMoritz Schulte <mo@g10code.com>2003-06-09 13:50:37 +0000
commit109ae59a947c8ed29ff8762c3afd34a3b51611c8 (patch)
tree2179db0e047dd70ffb577eeab4efb65a02c0f627 /cipher
parent6b2617d1f7a8869b4f544f9b1df4bfcf5d6db3a4 (diff)
downloadlibgcrypt-109ae59a947c8ed29ff8762c3afd34a3b51611c8.tar.gz
2003-06-08 Moritz Schulte <moritz@g10code.com>
* pubkey.c (gcry_pk_encrypt): Improve calculation for size of the format string. 2003-06-07 Moritz Schulte <moritz@g10code.com> * arcfour.c, bithelp.h, blowfish.c, cast5.c, cipher.c, crc.c, des.c, dsa.c, elgamal.c, md4.c, md5.c, md.c, primegen.c, pubkey.c, rand-internal.h, random.c, random.h, rijndael.c, rmd160.c, rmd160test.c, rmd.h, rndeged.c, rndlinux.c, rndunix.c, rndw32.c, rsa.c, sha1.c, sha256.c, sha512.c, tiger.c, twofish.c: Edited all preprocessor instructions to remove whitespace before the '#'. This is not required by C89, but there are some compilers out there that don't like it. Replaced any occurence of the now deprecated type names with the new ones. 2003-06-04 Moritz Schulte <moritz@g10code.com> * pubkey.c (gcry_pk_encrypt): Construct an arg_list and use gcry_sexp_build_array instead of gcry_sexp_build. (gcry_pk_sign): Likewise. (gcry_pk_genkey): Likewise. 2003-06-01 Moritz Schulte <moritz@g10code.com> * dsa.c (_gcry_dsa_generate): Do not check wether the algorithm ID does indeed belong to DSA. (_gcry_dsa_sign): Likewise. (_gcry_dsa_verify): Likewise. (_gcry_dsa_get_nbits): Likewise. * elgamal.c (_gcry_elg_check_secret_key): Do not check wether the algorithm ID does indeed belong to ElGamal. (_gcry_elg_encrypt): Likewise. (_gcry_elg_decrypt): Likewise. (_gcry_elg_sign): Likewise. (_gcry_elg_verify): Likewise. (_gcry_elg_get_nbits): Likewise. (_gcry_elg_generate): Likewise. * rsa.c (_gcry_rsa_generate): Do not check wether the algorithm ID does indeed belong to RSA. (_gcry_rsa_encrypt): Likewise. (_gcry_rsa_decrypt): Likewise. (_gcry_rsa_sign): Likewise. (_gcry_rsa_verify): Likewise. (_gcry_rsa_get_nbits): Likewise. 2003-05-30 Moritz Schulte <moritz@g10code.com> * md.c (md_get_algo): Return zero in case to algorithm is enabled. * md.c (gcry_md_info): Adjusted for new no-errno-API. (md_final): Likewise. (gcry_md_get_algo): Likewise. * pubkey.c (gcry_pk_get_keygrip): Likewise. (gcry_pk_ctl): Likewise. (gcry_pk_algo_info): Likewise. * des.c (selftest): Likewise. 2003-05-29 Moritz Schulte <moritz@g10code.com> * md.c (md_enable): Do not forget to release module on error. (gcry_md_open): Adjusted for new no-errno-API. (md_open): Likewise. (md_copy): Likewise. (gcry_md_copy): Likewise. (gcry_md_setkey): Likewise. (gcry_md_algo_info): Likewise. * cipher.c (gcry_cipher_open): Adjusted for new no-errno-API and also fixed a locking bug. (gcry_cipher_encrypt): Adjusted for new no-errno-API. (gcry_cipher_decrypt): Likewise. (gcry_cipher_ctl): Likewise. (gcry_cipher_info): Likewise. (gcry_cipher_algo_info): Likewise. 2003-05-28 Moritz Schulte <moritz@g10code.com> * md.c (md_enable): Adjusted for libgpg-error. (gcry_md_enable): Likewise. (gcry_digest_register_default): Likewise. (gcry_digest_register): Likewise. (check_digest_algo): Likewise. (prepare_macpads): Likewise. (gcry_md_setkey): Likewise. (gcry_md_ctl): Likewise. (gcry_md_get): Likewise. (gcry_md_algo_info): Likewise. (gcry_md_info): Likewise. * dsa.c (_gcry_dsa_generate): Likewise. (_gcry_dsa_check_secret_key): Likewise. (_gcry_dsa_sign): Likewie. (_gcry_dsa_verify): Likewise. * twofish.c (do_twofish_setkey): Likewise. (twofish_setkey): Likewise. * cipher.c (gcry_cipher_register): Likewise. 2003-05-25 Moritz Schulte <moritz@g10code.com> * rijndael.c (do_setkey): Adjusted for libgpg-error. (rijndael_setkey): Likewise. * random.c (gcry_random_add_bytes): Likewise. * elgamal.c (_gcry_elg_generate): Likewise. (_gcry_elg_check_secret_key): Likewise. (_gcry_elg_encrypt): Likewise. (_gcry_elg_decrypt): Likewise. (_gcry_elg_sign): Likewise. (_gcry_elg_verify): Likewise. * rsa.c (_gcry_rsa_generate): Likewise. (_gcry_rsa_check_secret_key): Likewise. (_gcry_rsa_encrypt): Likewise. (_gcry_rsa_decrypt): Likewise. (_gcry_rsa_sign): Likewise. (_gcry_rsa_verify): Likewise. * pubkey.c (dummy_generate, dummy_check_secret_key, dummy_encrypt, dummy_decrypt, dummy_sign, dummy_verify): Likewise. (gcry_pubkey_register): Likewise. (check_pubkey_algo): Likewise. (pubkey_generate): Likewise. (pubkey_check_secret_key): Likewise. (pubkey_encrypt): Likewise. (pubkey_decrypt): Likewise. (pubkey_sign): Likewise. (pubkey_verify): Likewise. (sexp_elements_extract): Likewise. (sexp_to_key): Likewise. (sexp_to_sig): Likewise. (sexp_to_enc): Likewise. (sexp_data_to_mpi): Likewise. (gcry_pk_encrypt): Likewise. (gcry_pk_decrypt): Likewise. (gcry_pk_sign): Likewise. (gcry_pk_verify): Likewise. (gcry_pk_testkey): Likewise. (gcry_pk_genkey): Likewise. (gcry_pk_ctl): Likewise. * cipher.c (dummy_setkey): Likewise. (check_cipher_algo): Likewise. (gcry_cipher_open): Likewise. (cipher_setkey): Likewise. (gcry_cipher_ctl): Likewise. (cipher_encrypt): Likewise. (gcry_cipher_encrypt): Likewise. (cipher_decrypt): Likewise. (gcry_cipher_decrypt): Likewise. (gcry_cipher_info): Likewise. (gcry_cipher_algo_info): Likewise. * cast5.c (cast_setkey): Likewise. (do_cast_setkey): Likewise. * arcfour.c (arcfour_setkey): Likewise. (do_arcfour_setkey): Likewise. * blowfish.c (do_bf_setkey): Likewise. (bf_setkey): Likewise. * des.c (do_des_setkey): Likewise. (do_tripledes_setkey): Likewise. 2003-05-22 Moritz Schulte <moritz@g10code.com> * tiger.c: Merged code ussing the U64_C macro from GnuPG. * sha512.c: Likewise. 2003-05-17 Moritz Schulte <moritz@g10code.com> * pubkey.c (gcry_pk_genkey): Fix type: acquire a lock, instead of releasing it. 2003-05-11 Moritz Schulte <moritz@g10code.com> * pubkey.c (gcry_pk_testkey): Call REGISTER_DEFAULT_CIPHERS. (gcry_pk_ctl): Likewise.
Diffstat (limited to 'cipher')
-rw-r--r--cipher/ChangeLog175
-rw-r--r--cipher/Makefile.am6
-rw-r--r--cipher/arcfour.c12
-rw-r--r--cipher/blowfish.c42
-rw-r--r--cipher/cast5.c65
-rw-r--r--cipher/cipher.c492
-rw-r--r--cipher/des.c28
-rw-r--r--cipher/dsa.c197
-rw-r--r--cipher/elgamal.c277
-rw-r--r--cipher/md.c566
-rw-r--r--cipher/md4.c12
-rw-r--r--cipher/md5.c12
-rw-r--r--cipher/primegen.c2
-rw-r--r--cipher/pubkey.c525
-rw-r--r--cipher/random.c97
-rw-r--r--cipher/rijndael.c24
-rw-r--r--cipher/rmd160.c16
-rw-r--r--cipher/rmd160test.c6
-rw-r--r--cipher/rndlinux.c20
-rw-r--r--cipher/rndunix.c30
-rw-r--r--cipher/rndw32.c10
-rw-r--r--cipher/rsa.c319
-rw-r--r--cipher/sha1.c18
-rw-r--r--cipher/sha512.c99
-rw-r--r--cipher/tiger.c1049
-rw-r--r--cipher/twofish.c8
26 files changed, 2193 insertions, 1914 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index e128d3e4..e66d0a28 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,178 @@
+2003-06-08 Moritz Schulte <moritz@g10code.com>
+
+ * pubkey.c (gcry_pk_encrypt): Improve calculation for size of the
+ format string.
+
+2003-06-07 Moritz Schulte <moritz@g10code.com>
+
+ * arcfour.c, bithelp.h, blowfish.c, cast5.c, cipher.c, crc.c,
+ des.c, dsa.c, elgamal.c, md4.c, md5.c, md.c, primegen.c, pubkey.c,
+ rand-internal.h, random.c, random.h, rijndael.c, rmd160.c,
+ rmd160test.c, rmd.h, rndeged.c, rndlinux.c, rndunix.c, rndw32.c,
+ rsa.c, sha1.c, sha256.c, sha512.c, tiger.c, twofish.c: Edited all
+ preprocessor instructions to remove whitespace before the '#'.
+ This is not required by C89, but there are some compilers out
+ there that don't like it. Replaced any occurence of the now
+ deprecated type names with the new ones.
+
+2003-06-04 Moritz Schulte <moritz@g10code.com>
+
+ * pubkey.c (gcry_pk_encrypt): Construct an arg_list and use
+ gcry_sexp_build_array instead of gcry_sexp_build.
+ (gcry_pk_sign): Likewise.
+ (gcry_pk_genkey): Likewise.
+
+2003-06-01 Moritz Schulte <moritz@g10code.com>
+
+ * dsa.c (_gcry_dsa_generate): Do not check wether the algorithm ID
+ does indeed belong to DSA.
+ (_gcry_dsa_sign): Likewise.
+ (_gcry_dsa_verify): Likewise.
+ (_gcry_dsa_get_nbits): Likewise.
+
+ * elgamal.c (_gcry_elg_check_secret_key): Do not check wether the
+ algorithm ID does indeed belong to ElGamal.
+ (_gcry_elg_encrypt): Likewise.
+ (_gcry_elg_decrypt): Likewise.
+ (_gcry_elg_sign): Likewise.
+ (_gcry_elg_verify): Likewise.
+ (_gcry_elg_get_nbits): Likewise.
+ (_gcry_elg_generate): Likewise.
+
+ * rsa.c (_gcry_rsa_generate): Do not check wether the algorithm ID
+ does indeed belong to RSA.
+ (_gcry_rsa_encrypt): Likewise.
+ (_gcry_rsa_decrypt): Likewise.
+ (_gcry_rsa_sign): Likewise.
+ (_gcry_rsa_verify): Likewise.
+ (_gcry_rsa_get_nbits): Likewise.
+
+2003-05-30 Moritz Schulte <moritz@g10code.com>
+
+ * md.c (md_get_algo): Return zero in case to algorithm is enabled.
+
+ * md.c (gcry_md_info): Adjusted for new no-errno-API.
+ (md_final): Likewise.
+ (gcry_md_get_algo): Likewise.
+ * pubkey.c (gcry_pk_get_keygrip): Likewise.
+ (gcry_pk_ctl): Likewise.
+ (gcry_pk_algo_info): Likewise.
+ * des.c (selftest): Likewise.
+
+2003-05-29 Moritz Schulte <moritz@g10code.com>
+
+ * md.c (md_enable): Do not forget to release module on error.
+ (gcry_md_open): Adjusted for new no-errno-API.
+ (md_open): Likewise.
+ (md_copy): Likewise.
+ (gcry_md_copy): Likewise.
+ (gcry_md_setkey): Likewise.
+ (gcry_md_algo_info): Likewise.
+
+ * cipher.c (gcry_cipher_open): Adjusted for new no-errno-API and
+ also fixed a locking bug.
+ (gcry_cipher_encrypt): Adjusted for new no-errno-API.
+ (gcry_cipher_decrypt): Likewise.
+ (gcry_cipher_ctl): Likewise.
+ (gcry_cipher_info): Likewise.
+ (gcry_cipher_algo_info): Likewise.
+
+2003-05-28 Moritz Schulte <moritz@g10code.com>
+
+ * md.c (md_enable): Adjusted for libgpg-error.
+ (gcry_md_enable): Likewise.
+ (gcry_digest_register_default): Likewise.
+ (gcry_digest_register): Likewise.
+ (check_digest_algo): Likewise.
+ (prepare_macpads): Likewise.
+ (gcry_md_setkey): Likewise.
+ (gcry_md_ctl): Likewise.
+ (gcry_md_get): Likewise.
+ (gcry_md_algo_info): Likewise.
+ (gcry_md_info): Likewise.
+ * dsa.c (_gcry_dsa_generate): Likewise.
+ (_gcry_dsa_check_secret_key): Likewise.
+ (_gcry_dsa_sign): Likewie.
+ (_gcry_dsa_verify): Likewise.
+ * twofish.c (do_twofish_setkey): Likewise.
+ (twofish_setkey): Likewise.
+ * cipher.c (gcry_cipher_register): Likewise.
+
+2003-05-25 Moritz Schulte <moritz@g10code.com>
+
+ * rijndael.c (do_setkey): Adjusted for libgpg-error.
+ (rijndael_setkey): Likewise.
+ * random.c (gcry_random_add_bytes): Likewise.
+ * elgamal.c (_gcry_elg_generate): Likewise.
+ (_gcry_elg_check_secret_key): Likewise.
+ (_gcry_elg_encrypt): Likewise.
+ (_gcry_elg_decrypt): Likewise.
+ (_gcry_elg_sign): Likewise.
+ (_gcry_elg_verify): Likewise.
+ * rsa.c (_gcry_rsa_generate): Likewise.
+ (_gcry_rsa_check_secret_key): Likewise.
+ (_gcry_rsa_encrypt): Likewise.
+ (_gcry_rsa_decrypt): Likewise.
+ (_gcry_rsa_sign): Likewise.
+ (_gcry_rsa_verify): Likewise.
+ * pubkey.c (dummy_generate, dummy_check_secret_key, dummy_encrypt,
+ dummy_decrypt, dummy_sign, dummy_verify): Likewise.
+ (gcry_pubkey_register): Likewise.
+ (check_pubkey_algo): Likewise.
+ (pubkey_generate): Likewise.
+ (pubkey_check_secret_key): Likewise.
+ (pubkey_encrypt): Likewise.
+ (pubkey_decrypt): Likewise.
+ (pubkey_sign): Likewise.
+ (pubkey_verify): Likewise.
+ (sexp_elements_extract): Likewise.
+ (sexp_to_key): Likewise.
+ (sexp_to_sig): Likewise.
+ (sexp_to_enc): Likewise.
+ (sexp_data_to_mpi): Likewise.
+ (gcry_pk_encrypt): Likewise.
+ (gcry_pk_decrypt): Likewise.
+ (gcry_pk_sign): Likewise.
+ (gcry_pk_verify): Likewise.
+ (gcry_pk_testkey): Likewise.
+ (gcry_pk_genkey): Likewise.
+ (gcry_pk_ctl): Likewise.
+ * cipher.c (dummy_setkey): Likewise.
+ (check_cipher_algo): Likewise.
+ (gcry_cipher_open): Likewise.
+ (cipher_setkey): Likewise.
+ (gcry_cipher_ctl): Likewise.
+ (cipher_encrypt): Likewise.
+ (gcry_cipher_encrypt): Likewise.
+ (cipher_decrypt): Likewise.
+ (gcry_cipher_decrypt): Likewise.
+ (gcry_cipher_info): Likewise.
+ (gcry_cipher_algo_info): Likewise.
+ * cast5.c (cast_setkey): Likewise.
+ (do_cast_setkey): Likewise.
+ * arcfour.c (arcfour_setkey): Likewise.
+ (do_arcfour_setkey): Likewise.
+ * blowfish.c (do_bf_setkey): Likewise.
+ (bf_setkey): Likewise.
+ * des.c (do_des_setkey): Likewise.
+ (do_tripledes_setkey): Likewise.
+
+2003-05-22 Moritz Schulte <moritz@g10code.com>
+
+ * tiger.c: Merged code ussing the U64_C macro from GnuPG.
+
+ * sha512.c: Likewise.
+
+2003-05-17 Moritz Schulte <moritz@g10code.com>
+
+ * pubkey.c (gcry_pk_genkey): Fix type: acquire a lock, instead of
+ releasing it.
+
+2003-05-11 Moritz Schulte <moritz@g10code.com>
+
+ * pubkey.c (gcry_pk_testkey): Call REGISTER_DEFAULT_CIPHERS.
+ (gcry_pk_ctl): Likewise.
+
2003-04-27 Moritz Schulte <moritz@g10code.com>
* pubkey.c (gcry_pk_genkey): Release sexp after extracted data has
diff --git a/cipher/Makefile.am b/cipher/Makefile.am
index 0be560c0..06c2807d 100644
--- a/cipher/Makefile.am
+++ b/cipher/Makefile.am
@@ -44,6 +44,9 @@ endif
if USE_TWOFISH
tmp_twofish = twofish.c
endif
+if USE_SERPENT
+ tmp_serpent = serpent.c
+endif
ciphers = \
$(tmp_arcfour) \
@@ -51,7 +54,8 @@ $(tmp_blowfish) \
$(tmp_cast5) \
$(tmp_des) \
$(tmp_aes) \
-$(tmp_twofish)
+$(tmp_twofish) \
+$(tmp_serpent)
if USE_DSA
tmp_dsa = dsa.c
diff --git a/cipher/arcfour.c b/cipher/arcfour.c
index 8e2ba4f0..d243414f 100644
--- a/cipher/arcfour.c
+++ b/cipher/arcfour.c
@@ -71,7 +71,7 @@ encrypt_stream (void *context,
}
-static int
+static gpg_err_code_t
do_arcfour_setkey (void *context, const byte *key, unsigned int keylen)
{
static int initialized;
@@ -87,10 +87,10 @@ do_arcfour_setkey (void *context, const byte *key, unsigned int keylen)
log_error ("ARCFOUR selftest failed (%s)\n", selftest_failed );
}
if( selftest_failed )
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
if( keylen < 40/8 ) /* we want at least 40 bits */
- return GCRYERR_INV_KEYLEN;
+ return GPG_ERR_INV_KEYLEN;
ctx->idx_i = ctx->idx_j = 0;
for (i=0; i < 256; i++ )
@@ -106,14 +106,14 @@ do_arcfour_setkey (void *context, const byte *key, unsigned int keylen)
}
memset( karr, 0, 256 );
- return 0;
+ return GPG_ERR_NO_ERROR;
}
-static int
+static gpg_err_code_t
arcfour_setkey ( void *context, const byte *key, unsigned int keylen )
{
ARCFOUR_context *ctx = (ARCFOUR_context *) context;
- int rc = do_arcfour_setkey (ctx, key, keylen );
+ gpg_err_code_t rc = do_arcfour_setkey (ctx, key, keylen );
_gcry_burn_stack (300);
return rc;
}
diff --git a/cipher/blowfish.c b/cipher/blowfish.c
index 707c9560..97cc1220 100644
--- a/cipher/blowfish.c
+++ b/cipher/blowfish.c
@@ -49,7 +49,7 @@ typedef struct {
u32 p[BLOWFISH_ROUNDS+2];
} BLOWFISH_context;
-static int bf_setkey (void *c, const byte *key, unsigned keylen);
+static gpg_err_code_t bf_setkey (void *c, const byte *key, unsigned keylen);
static void encrypt_block (void *bc, byte *outbuf, const byte *inbuf);
static void decrypt_block (void *bc, byte *outbuf, const byte *inbuf);
@@ -248,27 +248,27 @@ function_F( BLOWFISH_context *bc, u32 x )
{
u16 a, b, c, d;
- #ifdef BIG_ENDIAN_HOST
+#ifdef BIG_ENDIAN_HOST
a = ((byte*)&x)[0];
b = ((byte*)&x)[1];
c = ((byte*)&x)[2];
d = ((byte*)&x)[3];
- #else
+#else
a = ((byte*)&x)[3];
b = ((byte*)&x)[2];
c = ((byte*)&x)[1];
d = ((byte*)&x)[0];
- #endif
+#endif
return ((bc->s0[a] + bc->s1[b]) ^ bc->s2[c] ) + bc->s3[d];
}
#endif
#ifdef BIG_ENDIAN_HOST
- #define F(x) ((( s0[((byte*)&x)[0]] + s1[((byte*)&x)[1]]) \
+#define F(x) ((( s0[((byte*)&x)[0]] + s1[((byte*)&x)[1]]) \
^ s2[((byte*)&x)[2]]) + s3[((byte*)&x)[3]] )
#else
- #define F(x) ((( s0[((byte*)&x)[3]] + s1[((byte*)&x)[2]]) \
+#define F(x) ((( s0[((byte*)&x)[3]] + s1[((byte*)&x)[2]]) \
^ s2[((byte*)&x)[1]]) + s3[((byte*)&x)[0]] )
#endif
#define R(l,r,i) do { l ^= p[i]; r ^= F(l); } while(0)
@@ -276,7 +276,7 @@ function_F( BLOWFISH_context *bc, u32 x )
static void
do_encrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr )
{
- #if BLOWFISH_ROUNDS == 16
+#if BLOWFISH_ROUNDS == 16
u32 xl, xr, *s0, *s1, *s2, *s3, *p;
xl = *ret_xl;
@@ -310,7 +310,7 @@ do_encrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr )
*ret_xl = xr;
*ret_xr = xl;
- #else
+#else
u32 xl, xr, temp, *p;
int i;
@@ -334,14 +334,14 @@ do_encrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr )
*ret_xl = xl;
*ret_xr = xr;
- #endif
+#endif
}
static void
decrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr )
{
- #if BLOWFISH_ROUNDS == 16
+#if BLOWFISH_ROUNDS == 16
u32 xl, xr, *s0, *s1, *s2, *s3, *p;
xl = *ret_xl;
@@ -375,7 +375,7 @@ decrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr )
*ret_xl = xr;
*ret_xr = xl;
- #else
+#else
u32 xl, xr, temp, *p;
int i;
@@ -400,7 +400,7 @@ decrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr )
*ret_xl = xl;
*ret_xr = xr;
- #endif
+#endif
}
#undef F
@@ -490,7 +490,7 @@ selftest(void)
-static int
+static gpg_err_code_t
do_bf_setkey (BLOWFISH_context *c, const byte *key, unsigned keylen)
{
int i, j;
@@ -505,7 +505,7 @@ do_bf_setkey (BLOWFISH_context *c, const byte *key, unsigned keylen)
log_error ("%s\n", selftest_failed );
}
if( selftest_failed )
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
for(i=0; i < BLOWFISH_ROUNDS+2; i++ )
c->p[i] = ps[i];
@@ -517,17 +517,17 @@ do_bf_setkey (BLOWFISH_context *c, const byte *key, unsigned keylen)
}
for(i=j=0; i < BLOWFISH_ROUNDS+2; i++ ) {
- #ifdef BIG_ENDIAN_HOST
+#ifdef BIG_ENDIAN_HOST
((byte*)&data)[0] = key[j];
((byte*)&data)[1] = key[(j+1)%keylen];
((byte*)&data)[2] = key[(j+2)%keylen];
((byte*)&data)[3] = key[(j+3)%keylen];
- #else
+#else
((byte*)&data)[3] = key[j];
((byte*)&data)[2] = key[(j+1)%keylen];
((byte*)&data)[1] = key[(j+2)%keylen];
((byte*)&data)[0] = key[(j+3)%keylen];
- #endif
+#endif
c->p[i] ^= data;
j = (j+4) % keylen;
}
@@ -566,19 +566,19 @@ do_bf_setkey (BLOWFISH_context *c, const byte *key, unsigned keylen)
for( j=i+1; j < 256; j++) {
if( (c->s0[i] == c->s0[j]) || (c->s1[i] == c->s1[j]) ||
(c->s2[i] == c->s2[j]) || (c->s3[i] == c->s3[j]) )
- return GCRYERR_WEAK_KEY;
+ return GPG_ERR_WEAK_KEY;
}
}
- return 0;
+ return GPG_ERR_NO_ERROR;
}
-static int
+static gpg_err_code_t
bf_setkey (void *context, const byte *key, unsigned keylen)
{
BLOWFISH_context *c = (BLOWFISH_context *) context;
- int rc = do_bf_setkey (c, key, keylen);
+ gpg_err_code_t rc = do_bf_setkey (c, key, keylen);
_gcry_burn_stack (64);
return rc;
}
diff --git a/cipher/cast5.c b/cipher/cast5.c
index 89ff6cf2..8131c405 100644
--- a/cipher/cast5.c
+++ b/cipher/cast5.c
@@ -50,7 +50,7 @@ typedef struct {
byte Kr[16];
} CAST5_context;
-static int cast_setkey (void *c, const byte *key, unsigned keylen);
+static gpg_err_code_t cast_setkey (void *c, const byte *key, unsigned keylen);
static void encrypt_block (void *c, byte *outbuf, const byte *inbuf);
static void decrypt_block (void *c, byte *outbuf, const byte *inbuf);
@@ -341,7 +341,7 @@ rol(int n, u32 x)
return x;
}
#else
- #define rol(n,x) ( ((x) << (n)) | ((x) >> (32-(n))) )
+#define rol(n,x) ( ((x) << (n)) | ((x) >> (32-(n))) )
#endif
#define F1(D,m,r) ( (I = ((m) + (D))), (I=rol((r),I)), \
@@ -483,7 +483,7 @@ selftest(void)
if( memcmp( buffer, plain, 8 ) )
return "2";
- #if 0 /* full maintenance test */
+#if 0 /* full maintenance test */
{
int i;
byte a0[16] = { 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
@@ -507,7 +507,7 @@ selftest(void)
return "3";
}
- #endif
+#endif
return NULL;
}
@@ -517,8 +517,8 @@ static void
key_schedule( u32 *x, u32 *z, u32 *k )
{
- #define xi(i) ((x[(i)/4] >> (8*(3-((i)%4)))) & 0xff)
- #define zi(i) ((z[(i)/4] >> (8*(3-((i)%4)))) & 0xff)
+#define xi(i) ((x[(i)/4] >> (8*(3-((i)%4)))) & 0xff)
+#define zi(i) ((z[(i)/4] >> (8*(3-((i)%4)))) & 0xff)
z[0] = x[0] ^ s5[xi(13)]^s6[xi(15)]^s7[xi(12)]^s8[xi(14)]^s7[xi( 8)];
z[1] = x[2] ^ s5[zi( 0)]^s6[zi( 2)]^s7[zi( 1)]^s8[zi( 3)]^s8[xi(10)];
@@ -556,12 +556,12 @@ key_schedule( u32 *x, u32 *z, u32 *k )
k[14]= s5[xi(12)]^s6[xi(13)]^s7[xi( 3)]^s8[xi( 2)]^s7[xi( 8)];
k[15]= s5[xi(14)]^s6[xi(15)]^s7[xi( 1)]^s8[xi( 0)]^s8[xi(13)];
- #undef xi
- #undef zi
+#undef xi
+#undef zi
}
-static int
+static gpg_err_code_t
do_cast_setkey( CAST5_context *c, const byte *key, unsigned keylen )
{
static int initialized;
@@ -578,10 +578,10 @@ do_cast_setkey( CAST5_context *c, const byte *key, unsigned keylen )
log_error ("CAST5 selftest failed (%s).\n", selftest_failed );
}
if( selftest_failed )
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
if( keylen != 16 )
- return GCRYERR_INV_KEYLEN;
+ return GPG_ERR_INV_KEYLEN;
x[0] = key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3];
x[1] = key[4] << 24 | key[5] << 16 | key[6] << 8 | key[7];
@@ -599,54 +599,21 @@ do_cast_setkey( CAST5_context *c, const byte *key, unsigned keylen )
memset(&z,0, sizeof z);
memset(&k,0, sizeof k);
- #undef xi
- #undef zi
- return 0;
+#undef xi
+#undef zi
+ return GPG_ERR_NO_ERROR;
}
-static int
+static gpg_err_code_t
cast_setkey (void *context, const byte *key, unsigned keylen )
{
CAST5_context *c = (CAST5_context *) context;
- int rc = do_cast_setkey (c, key, keylen);
+ gpg_err_code_t rc = do_cast_setkey (c, key, keylen);
_gcry_burn_stack (96+7*sizeof(void*));
return rc;
}
-#if 0
-/****************
- * Return some information about the algorithm. We need algo here to
- * distinguish different flavors of the algorithm.
- * Returns: A pointer to string describing the algorithm or NULL if
- * the ALGO is invalid.
- */
-const char *
-_gcry_cast5_get_info( int algo, size_t *keylen,
- size_t *blocksize, size_t *contextsize,
- int (**r_setkey)( void *c, byte *key, unsigned keylen ),
- void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ),
- void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf )
- )
-{
- *keylen = 128;
- *blocksize = CAST5_BLOCKSIZE;
- *contextsize = sizeof(CAST5_context);
- *(int (**)(CAST5_context*, byte*, unsigned))r_setkey
- = cast_setkey;
- *(void (**)(CAST5_context*, byte*, byte*))r_encrypt
- = encrypt_block;
- *(void (**)(CAST5_context*, byte*, byte*))r_decrypt
- = decrypt_block;
-
-
- if( algo == GCRY_CIPHER_CAST5 )
- return "CAST5";
- return NULL;
-}
-
-#endif
-
GcryCipherSpec cipher_spec_cast5 =
{
"CAST5", GCRY_CIPHER_CAST5, CAST5_BLOCKSIZE, 128, sizeof (CAST5_context),
diff --git a/cipher/cipher.c b/cipher/cipher.c
index f7711fbe..4221a79e 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -123,10 +123,10 @@ static int default_ciphers_registered;
/* These dummy functions are used in case a cipher implementation
refuses to provide it's own functions. */
-static int
+static gpg_err_code_t
dummy_setkey (void *c, const unsigned char *key, unsigned keylen)
{
- return 0;
+ return GPG_ERR_NO_ERROR;
}
static void
@@ -164,7 +164,8 @@ dummy_decrypt_stream (void *c,
static void
gcry_cipher_register_default (void)
{
- int i, err = 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ int i;
for (i = 0; (! err) && cipher_table[i].cipher; i++)
{
@@ -249,18 +250,19 @@ gcry_cipher_id_new (void)
/* Public function. Register a provided CIPHER. Returns zero on
success, in which case the chosen cipher ID has been stored in
CIPHER, or an error code. */
-int
+gpg_error_t
gcry_cipher_register (GcryCipherSpec *cipher,
GcryModule **module)
{
- int id, err = 0;
+ gpg_err_code_t err = 0;
+ int id;
GcryModule *mod;
ath_mutex_lock (&ciphers_registered_lock);
id = gcry_cipher_id_new ();
if (! id)
- err = GCRYERR_INTERNAL; /* FIXME? */
+ err = GPG_ERR_INTERNAL; /* FIXME? */
else
{
cipher->id = id;
@@ -272,7 +274,7 @@ gcry_cipher_register (GcryCipherSpec *cipher,
if (! err)
*module = mod;
- return err;
+ return gpg_error (err);
}
/* Public function. Unregister the cipher identified by MODULE, which
@@ -437,11 +439,11 @@ disable_cipher_algo (int id)
* Return 0 if the cipher algo is available.
*/
-static int
+static gpg_err_code_t
check_cipher_algo (int id)
{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
GcryModule *cipher;
- int err = 0;
REGISTER_DEFAULT_CIPHERS;
@@ -450,11 +452,11 @@ check_cipher_algo (int id)
if (cipher)
{
if (cipher->flags & FLAG_MODULE_DISABLED)
- err = GCRYERR_INV_CIPHER_ALGO;
+ err = GPG_ERR_CIPHER_ALGO;
_gcry_module_release (cipher);
}
else
- err = GCRYERR_INV_CIPHER_ALGO;
+ err = GPG_ERR_CIPHER_ALGO;
ath_mutex_unlock (&ciphers_registered_lock);
return err;
@@ -515,136 +517,162 @@ cipher_get_blocksize (int id)
* if something goes wrong.
*/
-GCRY_CIPHER_HD
-gcry_cipher_open( int algo, int mode, unsigned int flags )
+gpg_error_t
+gcry_cipher_open (gcry_cipher_hd_t *handle,
+ int algo, int mode, unsigned int flags )
{
- GCRY_CIPHER_HD h;
- int secure = (flags & GCRY_CIPHER_SECURE);
- GcryCipherSpec *cipher;
- GcryModule *module;
+ int secure = (flags & GCRY_CIPHER_SECURE);
+ GcryCipherSpec *cipher = NULL;
+ GcryModule *module = NULL;
+ gpg_err_code_t err = 0;
+ gcry_cipher_hd_t h;
- fast_random_poll();
+ fast_random_poll();
+
+ REGISTER_DEFAULT_CIPHERS;
- REGISTER_DEFAULT_CIPHERS;
+ /* Fetch the according module and check wether the cipher is marked
+ available for use. */
+ ath_mutex_lock (&ciphers_registered_lock);
+ module = gcry_cipher_lookup_id (algo);
+ if (module)
+ {
+ /* Found module. */
- /* Fetch the according module and check wether the cipher is
- marked available for use. */
- ath_mutex_lock (&ciphers_registered_lock);
- module = gcry_cipher_lookup_id (algo);
- if (module)
- {
- if (module->flags & FLAG_MODULE_DISABLED)
- {
- set_lasterr (GCRYERR_INV_CIPHER_ALGO);
- _gcry_module_release (module);
- return NULL;
- }
- }
- else
- {
- set_lasterr (GCRYERR_INV_CIPHER_ALGO);
- return NULL;
- }
- cipher = (GcryCipherSpec *) module->spec;
- ath_mutex_unlock (&ciphers_registered_lock);
-
- /* check flags */
- if( (flags & ~(GCRY_CIPHER_SECURE|
- GCRY_CIPHER_ENABLE_SYNC|
- GCRY_CIPHER_CBC_CTS|
- GCRY_CIPHER_CBC_MAC)) ||
- (flags & GCRY_CIPHER_CBC_CTS & GCRY_CIPHER_CBC_MAC)) {
- set_lasterr( GCRYERR_INV_CIPHER_ALGO );
- return NULL;
+ if (module->flags & FLAG_MODULE_DISABLED)
+ {
+ /* Not available for use. */
+ err = GPG_ERR_CIPHER_ALGO;
+ _gcry_module_release (module);
+ }
+ else
+ cipher = (GcryCipherSpec *) module->spec;
}
+ else
+ err = GPG_ERR_CIPHER_ALGO;
+ ath_mutex_unlock (&ciphers_registered_lock);
- /* check that a valid mode has been requested */
- switch( mode ) {
+ /* check flags */
+ if ((! err)
+ && ((flags & ~(0
+ | GCRY_CIPHER_SECURE
+ | GCRY_CIPHER_ENABLE_SYNC
+ | GCRY_CIPHER_CBC_CTS
+ | GCRY_CIPHER_CBC_MAC))
+ || (flags & GCRY_CIPHER_CBC_CTS & GCRY_CIPHER_CBC_MAC)))
+ err = GPG_ERR_CIPHER_ALGO;
+
+ /* check that a valid mode has been requested */
+ if (! err)
+ switch (mode)
+ {
case GCRY_CIPHER_MODE_ECB:
case GCRY_CIPHER_MODE_CBC:
case GCRY_CIPHER_MODE_CFB:
case GCRY_CIPHER_MODE_CTR:
- if ((cipher->encrypt == dummy_encrypt_block)
+ if ((cipher->encrypt == dummy_encrypt_block)
|| (cipher->decrypt == dummy_decrypt_block))
- {
- set_lasterr( GCRYERR_INV_CIPHER_MODE );
- return NULL;
- }
- break;
+ err = GPG_ERR_INV_CIPHER_MODE;
+ break;
+
case GCRY_CIPHER_MODE_STREAM:
- if ((cipher->stencrypt == dummy_encrypt_stream)
+ if ((cipher->stencrypt == dummy_encrypt_stream)
|| (cipher->stdecrypt == dummy_decrypt_stream))
- {
- set_lasterr( GCRYERR_INV_CIPHER_MODE );
- return NULL;
- }
+ err = GPG_ERR_INV_CIPHER_MODE;
break;
+
case GCRY_CIPHER_MODE_NONE:
/* FIXME: issue a warning when this mode is used */
break;
+
default:
- set_lasterr( GCRYERR_INV_CIPHER_MODE );
- return NULL;
+ err = GPG_ERR_INV_CIPHER_MODE;
+ }
+
+ /* ? FIXME: perform selftest here and mark this with a flag in
+ cipher_table ? */
+
+ if (! err)
+ {
+ size_t size = sizeof (*h)
+ + 2 * cipher->contextsize
+ - sizeof (PROPERLY_ALIGNED_TYPE);
+
+ if (secure)
+ h = gcry_calloc_secure (1, size);
+ else
+ h = gcry_calloc (1, size);
+
+ if (! h)
+ err = gpg_err_code_from_errno (errno);
+ else
+ {
+ h->magic = secure ? CTX_MAGIC_SECURE : CTX_MAGIC_NORMAL;
+ h->cipher = cipher;
+ h->module = module;
+ h->mode = mode;
+ h->flags = flags;
+ }
}
- /* ? perform selftest here and mark this with a flag in cipher_table ? */
-
- h = secure ? gcry_calloc_secure( 1,
- sizeof *h
- + 2 * cipher->contextsize
- - sizeof (PROPERLY_ALIGNED_TYPE) )
- : gcry_calloc( 1,
- sizeof *h
- + 2 * cipher->contextsize
- - sizeof (PROPERLY_ALIGNED_TYPE) );
- if( !h ) {
- set_lasterr( GCRYERR_NO_MEM );
- return NULL;
+ /* Done. */
+
+ if (err)
+ {
+ if (module)
+ {
+ /* Release module. */
+ ath_mutex_lock (&ciphers_registered_lock);
+ _gcry_module_release (module);
+ ath_mutex_unlock (&ciphers_registered_lock);
+ }
}
- h->magic = secure ? CTX_MAGIC_SECURE : CTX_MAGIC_NORMAL;
- h->cipher = cipher;
- h->module = module;
- h->mode = mode;
- h->flags = flags;
+ else
+ *handle = h;
- return h;
+ return gpg_error (err);
}
void
-gcry_cipher_close( GCRY_CIPHER_HD h )
+gcry_cipher_close (gcry_cipher_hd_t h)
{
- if( !h )
- return;
- if( h->magic != CTX_MAGIC_SECURE && h->magic != CTX_MAGIC_NORMAL )
- _gcry_fatal_error(GCRYERR_INTERNAL,
- "gcry_cipher_close: already closed/invalid handle");
+ if (! h)
+ return;
+ if ((h->magic != CTX_MAGIC_SECURE)
+ && (h->magic != CTX_MAGIC_NORMAL))
+ _gcry_fatal_error(GPG_ERR_INTERNAL,
+ "gcry_cipher_close: already closed/invalid handle");
+ else
h->magic = 0;
- ath_mutex_lock (&ciphers_registered_lock);
- _gcry_module_release (h->module);
- ath_mutex_unlock (&ciphers_registered_lock);
- gcry_free(h);
+ /* Release module. */
+ ath_mutex_lock (&ciphers_registered_lock);
+ _gcry_module_release (h->module);
+ ath_mutex_unlock (&ciphers_registered_lock);
+
+ gcry_free (h);
}
-static int
-cipher_setkey( GCRY_CIPHER_HD c, byte *key, unsigned keylen )
+static gpg_error_t
+cipher_setkey (gcry_cipher_hd_t c, byte *key, unsigned keylen)
{
- int ret;
-
- ret = (*c->cipher->setkey)( &c->context.c, key, keylen );
- if (! ret)
- memcpy ((void *) ((char *) &c->context.c
- + c->cipher->contextsize),
- (void *) &c->context.c,
- c->cipher->contextsize);
- return ret;
+ gpg_err_code_t ret;
+
+ ret = (*c->cipher->setkey) (&c->context.c, key, keylen);
+ if (! ret)
+ /* Duplicate initial context. */
+ memcpy ((void *) ((char *) &c->context.c + c->cipher->contextsize),
+ (void *) &c->context.c,
+ c->cipher->contextsize);
+
+ return gpg_error (ret);
}
static void
-cipher_setiv( GCRY_CIPHER_HD c, const byte *iv, unsigned ivlen )
+cipher_setiv( gcry_cipher_hd_t c, const byte *iv, unsigned ivlen )
{
memset( c->iv, 0, c->cipher->blocksize );
if( iv ) {
@@ -660,11 +688,10 @@ cipher_setiv( GCRY_CIPHER_HD c, const byte *iv, unsigned ivlen )
static void
-cipher_reset (GCRY_CIPHER_HD c)
+cipher_reset (gcry_cipher_hd_t c)
{
memcpy ((void *) &c->context.c,
- (void *) ((char *) &c->context.c
- + c->cipher->contextsize),
+ (void *) ((char *) &c->context.c + c->cipher->contextsize),
c->cipher->contextsize);
memset (c->iv, 0, c->cipher->blocksize);
memset (c->lastiv, 0, c->cipher->blocksize);
@@ -673,7 +700,7 @@ cipher_reset (GCRY_CIPHER_HD c)
static void
-do_ecb_encrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nblocks )
+do_ecb_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nblocks )
{
unsigned n;
@@ -685,7 +712,7 @@ do_ecb_encrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nblo
}
static void
-do_ecb_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nblocks )
+do_ecb_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nblocks )
{
unsigned n;
@@ -697,7 +724,7 @@ do_ecb_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nblo
}
static void
-do_cbc_encrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbytes )
+do_cbc_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nbytes )
{
unsigned int n;
byte *ivp;
@@ -746,7 +773,7 @@ do_cbc_encrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbyt
}
static void
-do_cbc_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbytes )
+do_cbc_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nbytes )
{
unsigned int n;
byte *ivp;
@@ -801,7 +828,7 @@ do_cbc_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbyt
static void
-do_cfb_encrypt( GCRY_CIPHER_HD c,
+do_cfb_encrypt( gcry_cipher_hd_t c,
byte *outbuf, const byte *inbuf, unsigned nbytes )
{
byte *ivp;
@@ -846,7 +873,7 @@ do_cfb_encrypt( GCRY_CIPHER_HD c,
}
static void
-do_cfb_decrypt( GCRY_CIPHER_HD c,
+do_cfb_decrypt( gcry_cipher_hd_t c,
byte *outbuf, const byte *inbuf, unsigned nbytes )
{
byte *ivp;
@@ -905,7 +932,7 @@ do_cfb_decrypt( GCRY_CIPHER_HD c,
static void
-do_ctr_encrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbytes )
+do_ctr_encrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nbytes )
{
unsigned int n;
byte tmp[MAX_BLOCKSIZE];
@@ -931,7 +958,7 @@ do_ctr_encrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbyt
}
static void
-do_ctr_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbytes )
+do_ctr_decrypt( gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf, unsigned nbytes )
{
return do_ctr_encrypt (c, outbuf, inbuf, nbytes);
}
@@ -942,25 +969,25 @@ do_ctr_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf, unsigned nbyt
* inbuf and outbuf may overlap or be the same.
* Depending on the mode some contraints apply to NBYTES.
*/
-static int
-cipher_encrypt( GCRY_CIPHER_HD c, byte *outbuf,
- const byte *inbuf, unsigned int nbytes )
+static gpg_err_code_t
+cipher_encrypt (gcry_cipher_hd_t c, byte *outbuf,
+ const byte *inbuf, unsigned int nbytes)
{
- int rc = 0;
+ gpg_err_code_t rc = GPG_ERR_NO_ERROR;
switch( c->mode ) {
case GCRY_CIPHER_MODE_ECB:
if (!(nbytes%c->cipher->blocksize))
do_ecb_encrypt(c, outbuf, inbuf, nbytes/c->cipher->blocksize );
else
- rc = GCRYERR_INV_ARG;
+ rc = GPG_ERR_INV_ARG;
break;
case GCRY_CIPHER_MODE_CBC:
if (!(nbytes%c->cipher->blocksize) || (nbytes > c->cipher->blocksize &&
(c->flags & GCRY_CIPHER_CBC_CTS)))
do_cbc_encrypt(c, outbuf, inbuf, nbytes );
else
- rc = GCRYERR_INV_ARG;
+ rc = GPG_ERR_INV_ARG;
break;
case GCRY_CIPHER_MODE_CFB:
do_cfb_encrypt(c, outbuf, inbuf, nbytes );
@@ -978,7 +1005,7 @@ cipher_encrypt( GCRY_CIPHER_HD c, byte *outbuf,
break;
default:
log_fatal("cipher_encrypt: invalid mode %d\n", c->mode );
- rc = GCRYERR_INV_CIPHER_MODE;
+ rc = GPG_ERR_INV_CIPHER_MODE;
break;
}
return rc;
@@ -989,41 +1016,34 @@ cipher_encrypt( GCRY_CIPHER_HD c, byte *outbuf,
* Encrypt IN and write it to OUT. If IN is NULL, in-place encryption has
* been requested,
*/
-int
-gcry_cipher_encrypt (GcryCipherHd h, byte *out, size_t outsize,
- const byte *in, size_t inlen )
+gpg_error_t
+gcry_cipher_encrypt (gcry_cipher_hd_t h, byte *out, size_t outsize,
+ const byte *in, size_t inlen)
{
- int rc;
+ gpg_err_code_t err;
if (!in)
- {
- /* caller requested in-place encryption */
- /* actullay cipher_encrypt() does not need to know about it, but
- * we may change this to get better performace */
- rc = cipher_encrypt ( h, out, out, outsize );
- }
+ /* caller requested in-place encryption */
+ /* actullay cipher_encrypt() does not need to know about it, but
+ * we may change this to get better performace */
+ err = cipher_encrypt (h, out, out, outsize);
+ else if (outsize < ((h->flags & GCRY_CIPHER_CBC_MAC) ? h->cipher->blocksize : inlen))
+ err = GPG_ERR_TOO_SHORT;
+ else if ((h->mode == GCRY_CIPHER_MODE_ECB
+ || (h->mode == GCRY_CIPHER_MODE_CBC
+ && (! ((h->flags & GCRY_CIPHER_CBC_CTS)
+ && (inlen > h->cipher->blocksize)))))
+ && (inlen % h->cipher->blocksize))
+ err = GPG_ERR_INV_ARG;
else
- {
- if ( outsize < ((h->flags & GCRY_CIPHER_CBC_MAC) ? h->cipher->blocksize : inlen))
- rc = GCRYERR_TOO_SHORT;
- else if ((h->mode == GCRY_CIPHER_MODE_ECB
- || (h->mode == GCRY_CIPHER_MODE_CBC
- && !((h->flags & GCRY_CIPHER_CBC_CTS)
- && (inlen > h->cipher->blocksize))
- )
- )
- && (inlen % h->cipher->blocksize))
- rc = GCRYERR_INV_ARG;
- else
- rc = cipher_encrypt (h, out, in, inlen);
- }
+ err = cipher_encrypt (h, out, in, inlen);
- if (rc && out)
+ if (err && out)
memset (out, 0x42, outsize); /* Failsafe: Make sure that the
plaintext will never make it into
OUT. */
- return rc? set_lasterr (rc):0;
+ return gpg_error (err);
}
@@ -1033,25 +1053,25 @@ gcry_cipher_encrypt (GcryCipherHd h, byte *out, size_t outsize,
* inbuf and outbuf may overlap or be the same.
* Depending on the mode some some contraints apply to NBYTES.
*/
-static int
-cipher_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf,
- unsigned nbytes )
+static gpg_err_code_t
+cipher_decrypt (gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf,
+ unsigned nbytes)
{
- int rc = 0;
+ gpg_err_code_t rc = GPG_ERR_NO_ERROR;
switch( c->mode ) {
case GCRY_CIPHER_MODE_ECB:
if (!(nbytes%c->cipher->blocksize))
do_ecb_decrypt(c, outbuf, inbuf, nbytes/c->cipher->blocksize );
else
- rc = GCRYERR_INV_ARG;
+ rc = GPG_ERR_INV_ARG;
break;
case GCRY_CIPHER_MODE_CBC:
if (!(nbytes%c->cipher->blocksize) || (nbytes > c->cipher->blocksize &&
(c->flags & GCRY_CIPHER_CBC_CTS)))
do_cbc_decrypt(c, outbuf, inbuf, nbytes );
else
- rc = GCRYERR_INV_ARG;
+ rc = GPG_ERR_INV_ARG;
break;
case GCRY_CIPHER_MODE_CFB:
do_cfb_decrypt(c, outbuf, inbuf, nbytes );
@@ -1069,38 +1089,36 @@ cipher_decrypt( GCRY_CIPHER_HD c, byte *outbuf, const byte *inbuf,
break;
default:
log_fatal ("cipher_decrypt: invalid mode %d\n", c->mode );
- rc = GCRYERR_INV_CIPHER_MODE;
+ rc = GPG_ERR_INV_CIPHER_MODE;
break;
}
return rc;
}
-int
-gcry_cipher_decrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
- const byte *in, size_t inlen )
+gpg_error_t
+gcry_cipher_decrypt (gcry_cipher_hd_t h, byte *out, size_t outsize,
+ const byte *in, size_t inlen)
{
- int rc;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
+ if (! in)
+ /* caller requested in-place encryption */
+ /* actullay cipher_encrypt() does not need to know about it, but
+ * we may chnage this to get better performace */
+ err = cipher_decrypt (h, out, out, outsize);
+ else if (outsize < inlen)
+ err = GPG_ERR_TOO_SHORT;
+ else if (((h->mode == GCRY_CIPHER_MODE_ECB)
+ || ((h->mode == GCRY_CIPHER_MODE_CBC)
+ && (! ((h->flags & GCRY_CIPHER_CBC_CTS)
+ && (inlen > h->cipher->blocksize)))))
+ && (inlen % h->cipher->blocksize) != 0)
+ err = GPG_ERR_INV_ARG;
+ else
+ err = cipher_decrypt (h, out, in, inlen);
- if( !in ) {
- /* caller requested in-place encryption */
- /* actullay cipher_encrypt() does not need to know about it, but
- * we may chnage this to get better performace */
- rc = cipher_decrypt( h, out, out, outsize );
- }
- else {
- if( outsize < inlen )
- return set_lasterr( GCRYERR_TOO_SHORT );
- if ( ( h->mode == GCRY_CIPHER_MODE_ECB ||
- (h->mode == GCRY_CIPHER_MODE_CBC &&
- !((h->flags & GCRY_CIPHER_CBC_CTS) &&
- (inlen > h->cipher->blocksize)))) &&
- (inlen % h->cipher->blocksize) != 0 )
- return set_lasterr( GCRYERR_INV_ARG );
-
- rc = cipher_decrypt( h, out, in, inlen );
- }
- return rc? set_lasterr (rc):0;
+ return gpg_error (err);
}
@@ -1110,7 +1128,7 @@ gcry_cipher_decrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
* the corresponding flag is set.
*/
static void
-cipher_sync( GCRY_CIPHER_HD c )
+cipher_sync( gcry_cipher_hd_t c )
{
if( (c->flags & GCRY_CIPHER_ENABLE_SYNC) && c->unused ) {
memmove(c->iv + c->unused, c->iv, c->cipher->blocksize - c->unused );
@@ -1120,10 +1138,10 @@ cipher_sync( GCRY_CIPHER_HD c )
}
-int
-gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t buflen)
+gpg_error_t
+gcry_cipher_ctl( gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen)
{
- int rc = 0;
+ gpg_err_code_t rc = GPG_ERR_NO_ERROR;
switch (cmd)
{
@@ -1142,7 +1160,7 @@ gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t buflen)
case GCRYCTL_SET_CBC_CTS:
if (buflen)
if (h->flags & GCRY_CIPHER_CBC_MAC)
- rc = GCRYERR_INV_FLAG;
+ rc = GPG_ERR_INV_FLAG;
else
h->flags |= GCRY_CIPHER_CBC_CTS;
else
@@ -1151,7 +1169,7 @@ gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t buflen)
case GCRYCTL_SET_CBC_MAC:
if (buflen)
if (h->flags & GCRY_CIPHER_CBC_CTS)
- rc = GCRYERR_INV_FLAG;
+ rc = GPG_ERR_INV_FLAG;
else
h->flags |= GCRY_CIPHER_CBC_MAC;
else
@@ -1162,7 +1180,7 @@ gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t buflen)
* integer with the algo number.
*/
if( h || !buffer || buflen != sizeof(int) )
- return set_lasterr( GCRYERR_INV_CIPHER_ALGO );
+ return gpg_error (GPG_ERR_CIPHER_ALGO);
disable_cipher_algo( *(int*)buffer );
break;
case GCRYCTL_SET_CTR:
@@ -1171,30 +1189,31 @@ gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t buflen)
else if (buffer == NULL || buflen == 0)
memset (h->ctr, 0, h->cipher->blocksize);
else
- rc = GCRYERR_INV_ARG;
+ rc = GPG_ERR_INV_ARG;
break;
default:
- rc = GCRYERR_INV_OP;
+ rc = GPG_ERR_INV_OP;
}
- return set_lasterr (rc);
+ return gpg_error (rc);
}
/****************
* Return information about the cipher handle.
- * -1 is returned on error and gcry_errno() may be used to get more information
- * about the error.
*/
-int
-gcry_cipher_info( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t *nbytes)
+gpg_error_t
+gcry_cipher_info( gcry_cipher_hd_t h, int cmd, void *buffer, size_t *nbytes)
{
- switch( cmd ) {
- default:
- set_lasterr( GCRYERR_INV_OP );
- return -1;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
+ switch (cmd)
+ {
+ default:
+ err = GPG_ERR_INV_OP;
}
- return 0;
+
+ return gpg_error (err);
}
/****************
@@ -1213,57 +1232,60 @@ gcry_cipher_info( GCRY_CIPHER_HD h, int cmd, void *buffer, size_t *nbytes)
* Returns 0 when the specified algorithm is available for use.
* buffer and nbytes must be zero.
*
- * On error the value -1 is returned and the error reason may be
- * retrieved by gcry_errno().
* Note: Because this function is in most cases used to return an
* integer value, we can make it easier for the caller to just look at
* the return value. The caller will in all cases consult the value
* and thereby detecting whether a error occured or not (i.e. while checking
* the block size)
*/
-int
-gcry_cipher_algo_info( int algo, int what, void *buffer, size_t *nbytes)
+gpg_error_t
+gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes)
{
- unsigned int ui;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ unsigned int ui;
- switch( what ) {
- case GCRYCTL_GET_KEYLEN:
- if( buffer || nbytes ) {
- set_lasterr( GCRYERR_INV_CIPHER_ALGO );
- break;
+ switch (what)
+ {
+ case GCRYCTL_GET_KEYLEN:
+ if (buffer || (! nbytes))
+ err = GPG_ERR_CIPHER_ALGO;
+ else
+ {
+ ui = cipher_get_keylen (algo);
+ if ((ui > 0) && (ui <= 512))
+ *nbytes = (size_t) ui / 8;
+ else
+ /* The only reason is an invalid algo or a strange
+ blocksize. */
+ err = GPG_ERR_CIPHER_ALGO;
}
- ui = cipher_get_keylen( algo );
- if( ui > 0 && ui <= 512 )
- return (int)ui/8;
- /* the only reason is an invalid algo or a strange blocksize */
- set_lasterr( GCRYERR_INV_CIPHER_ALGO );
- break;
+ break;
- case GCRYCTL_GET_BLKLEN:
- if( buffer || nbytes ) {
- set_lasterr( GCRYERR_INV_CIPHER_ALGO );
- break;
+ case GCRYCTL_GET_BLKLEN:
+ if (buffer || (! nbytes))
+ err = GPG_ERR_CIPHER_ALGO;
+ else
+ {
+ ui = cipher_get_blocksize (algo);
+ if ((ui > 0) && (ui < 10000))
+ *nbytes = ui;
+ else
+ /* The only reason is an invalid algo or a strange
+ blocksize. */
+ err = GPG_ERR_CIPHER_ALGO;
}
- ui = cipher_get_blocksize( algo );
- if( ui > 0 && ui < 10000 )
- return (int)ui;
- /* the only reason is an invalid algo or a strange blocksize */
- set_lasterr( GCRYERR_INV_CIPHER_ALGO );
- break;
+ break;
- case GCRYCTL_TEST_ALGO:
- if( buffer || nbytes ) {
- set_lasterr( GCRYERR_INV_ARG );
- break;
- }
- if( check_cipher_algo( algo ) ) {
- set_lasterr( GCRYERR_INV_CIPHER_ALGO );
- break;
- }
- return 0;
+ case GCRYCTL_TEST_ALGO:
+ if (buffer || nbytes)
+ err = GPG_ERR_INV_ARG;
+ else
+ err = check_cipher_algo (algo);
+ break;
default:
- set_lasterr( GCRYERR_INV_OP );
+ err = GPG_ERR_INV_OP;
}
- return -1;
+
+ return gpg_error (err);
}
diff --git a/cipher/des.c b/cipher/des.c
index 250818e1..80d4661b 100644
--- a/cipher/des.c
+++ b/cipher/des.c
@@ -573,7 +573,7 @@ des_setkey (struct _des_ctx *ctx, const byte * key)
#ifdef FIXME
if( selftest_failed )
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
#endif
des_key_schedule (key, ctx->encrypt_subkeys);
@@ -950,11 +950,11 @@ selftest (void)
{
int i;
unsigned char *p;
+ gcry_md_hd_t h;
- GCRY_MD_HD h = gcry_md_open (GCRY_MD_SHA1, 0);
-
- if (!h)
+ if (gcry_md_open (&h, GCRY_MD_SHA1, 0))
return "SHA1 not available";
+
for (i = 0; i < 64; ++i)
gcry_md_write (h, weak_keys[i], 8);
p = gcry_md_read (h, GCRY_MD_SHA1);
@@ -972,28 +972,28 @@ selftest (void)
}
-static int
+static gpg_err_code_t
do_tripledes_setkey ( void *context, const byte *key, unsigned keylen )
{
struct _tripledes_ctx *ctx = (struct _tripledes_ctx *) context;
#ifdef FIXME
if( selftest_failed )
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
#endif
if( keylen != 24 )
- return GCRYERR_INV_KEYLEN;
+ return GPG_ERR_INV_KEYLEN;
tripledes_set3keys ( ctx, key, key+8, key+16);
if( is_weak_key( key ) || is_weak_key( key+8 ) || is_weak_key( key+16 ) ) {
_gcry_burn_stack (64);
- return GCRYERR_WEAK_KEY;
+ return GPG_ERR_WEAK_KEY;
}
_gcry_burn_stack (64);
- return 0;
+ return GPG_ERR_NO_ERROR;
}
@@ -1014,7 +1014,7 @@ do_tripledes_decrypt( void *context, byte *outbuf, const byte *inbuf )
_gcry_burn_stack (32);
}
-static int
+static gpg_err_code_t
do_des_setkey (void *context, const byte *key, unsigned keylen)
{
struct _des_ctx *ctx = (struct _des_ctx *) context;
@@ -1029,20 +1029,20 @@ do_des_setkey (void *context, const byte *key, unsigned keylen)
log_error ("%s\n", selftest_failed);
}
if (selftest_failed)
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
if (keylen != 8)
- return GCRYERR_INV_KEYLEN;
+ return GPG_ERR_INV_KEYLEN;
des_setkey (ctx, key);
if (is_weak_key (key)) {
_gcry_burn_stack (64);
- return GCRYERR_WEAK_KEY;
+ return GPG_ERR_WEAK_KEY;
}
_gcry_burn_stack (64);
- return 0;
+ return GPG_ERR_NO_ERROR;
}
diff --git a/cipher/dsa.c b/cipher/dsa.c
index 4bc2cd03..417e9322 100644
--- a/cipher/dsa.c
+++ b/cipher/dsa.c
@@ -28,47 +28,49 @@
#include "mpi.h"
#include "cipher.h"
-typedef struct {
- MPI p; /* prime */
- MPI q; /* group order */
- MPI g; /* group generator */
- MPI y; /* g^x mod p */
+typedef struct
+{
+ MPI p; /* prime */
+ MPI q; /* group order */
+ MPI g; /* group generator */
+ MPI y; /* g^x mod p */
} DSA_public_key;
-typedef struct {
- MPI p; /* prime */
- MPI q; /* group order */
- MPI g; /* group generator */
- MPI y; /* g^x mod p */
- MPI x; /* secret exponent */
+typedef struct
+{
+ MPI p; /* prime */
+ MPI q; /* group order */
+ MPI g; /* group generator */
+ MPI y; /* g^x mod p */
+ MPI x; /* secret exponent */
} DSA_secret_key;
-static MPI gen_k( MPI q );
-static void test_keys( DSA_secret_key *sk, unsigned qbits );
-static int check_secret_key( DSA_secret_key *sk );
-static void generate( DSA_secret_key *sk, unsigned nbits, MPI **ret_factors );
-static void sign(MPI r, MPI s, MPI input, DSA_secret_key *skey);
-static int verify(MPI r, MPI s, MPI input, DSA_public_key *pkey);
+static MPI gen_k (MPI q);
+static void test_keys (DSA_secret_key *sk, unsigned qbits);
+static int check_secret_key (DSA_secret_key *sk);
+static void generate (DSA_secret_key *sk, unsigned nbits, MPI **ret_factors);
+static void sign (MPI r, MPI s, MPI input, DSA_secret_key *skey);
+static int verify (MPI r, MPI s, MPI input, DSA_public_key *pkey);
static void (*progress_cb) (void *,const char *, int, int, int );
static void *progress_cb_data;
void
-_gcry_register_pk_dsa_progress ( void (*cb)( void *,const char *, int,int,int),
- void *cb_data )
+_gcry_register_pk_dsa_progress (void (*cb) (void *, const char *, int, int, int),
+ void *cb_data)
{
- progress_cb = cb;
- progress_cb_data = cb_data;
+ progress_cb = cb;
+ progress_cb_data = cb_data;
}
static void
-progress( int c )
+progress (int c)
{
if (progress_cb)
- progress_cb ( progress_cb_data, "pk_dsa", c, 0, 0);
+ progress_cb (progress_cb_data, "pk_dsa", c, 0, 0);
}
@@ -354,98 +356,97 @@ verify(MPI r, MPI s, MPI hash, DSA_public_key *pkey )
************** interface ******************
*********************************************/
-int
-_gcry_dsa_generate( int algo, unsigned nbits, unsigned long dummy,
- MPI *skey, MPI **retfactors )
+gpg_err_code_t
+_gcry_dsa_generate (int algo, unsigned nbits, unsigned long dummy,
+ MPI *skey, MPI **retfactors)
{
- DSA_secret_key sk;
-
- if( algo != GCRY_PK_DSA )
- return GCRYERR_INV_PK_ALGO;
-
- generate( &sk, nbits, retfactors );
- skey[0] = sk.p;
- skey[1] = sk.q;
- skey[2] = sk.g;
- skey[3] = sk.y;
- skey[4] = sk.x;
- return 0;
+ DSA_secret_key sk;
+
+ generate (&sk, nbits, retfactors);
+ skey[0] = sk.p;
+ skey[1] = sk.q;
+ skey[2] = sk.g;
+ skey[3] = sk.y;
+ skey[4] = sk.x;
+
+ return GPG_ERR_NO_ERROR;
}
-int
-_gcry_dsa_check_secret_key( int algo, MPI *skey )
+gpg_err_code_t
+_gcry_dsa_check_secret_key (int algo, MPI *skey)
{
- DSA_secret_key sk;
-
- if( algo != GCRY_PK_DSA )
- return GCRYERR_INV_PK_ALGO;
- if( !skey[0] || !skey[1] || !skey[2] || !skey[3] || !skey[4] )
- return GCRYERR_BAD_MPI;
-
- sk.p = skey[0];
- sk.q = skey[1];
- sk.g = skey[2];
- sk.y = skey[3];
- sk.x = skey[4];
- if( !check_secret_key( &sk ) )
- return GCRYERR_BAD_SECRET_KEY;
-
- return 0;
-}
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ DSA_secret_key sk;
+
+ if ((! skey[0]) || (! skey[1]) || (! skey[2]) || (! skey[3]) || (! skey[4]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ sk.p = skey[0];
+ sk.q = skey[1];
+ sk.g = skey[2];
+ sk.y = skey[3];
+ sk.x = skey[4];
+ if (! check_secret_key (&sk))
+ err = GPG_ERR_BAD_SECKEY;
+ }
+ return err;
+}
-int
-_gcry_dsa_sign( int algo, MPI *resarr, MPI data, MPI *skey )
+gpg_err_code_t
+_gcry_dsa_sign (int algo, MPI *resarr, MPI data, MPI *skey)
{
- DSA_secret_key sk;
-
- if( algo != GCRY_PK_DSA )
- return GCRYERR_INV_PK_ALGO;
- if( !data || !skey[0] || !skey[1] || !skey[2] || !skey[3] || !skey[4] )
- return GCRYERR_BAD_MPI;
-
- sk.p = skey[0];
- sk.q = skey[1];
- sk.g = skey[2];
- sk.y = skey[3];
- sk.x = skey[4];
- resarr[0] = mpi_alloc( mpi_get_nlimbs( sk.p ) );
- resarr[1] = mpi_alloc( mpi_get_nlimbs( sk.p ) );
- sign( resarr[0], resarr[1], data, &sk );
- return 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ DSA_secret_key sk;
+
+ if ((! data)
+ || (! skey[0]) || (! skey[1]) || (! skey[2])
+ || (! skey[3]) || (! skey[4]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ sk.p = skey[0];
+ sk.q = skey[1];
+ sk.g = skey[2];
+ sk.y = skey[3];
+ sk.x = skey[4];
+ resarr[0] = mpi_alloc (mpi_get_nlimbs (sk.p));
+ resarr[1] = mpi_alloc (mpi_get_nlimbs (sk.p));
+ sign (resarr[0], resarr[1], data, &sk);
+ }
+ return err;
}
-int
-_gcry_dsa_verify( int algo, MPI hash, MPI *data, MPI *pkey,
- int (*cmp)(void *, MPI), void *opaquev )
+gpg_err_code_t
+_gcry_dsa_verify (int algo, MPI hash, MPI *data, MPI *pkey,
+ int (*cmp) (void *, MPI), void *opaquev)
{
- DSA_public_key pk;
-
- if( algo != GCRY_PK_DSA )
- return GCRYERR_INV_PK_ALGO;
- if( !data[0] || !data[1] || !hash
- || !pkey[0] || !pkey[1] || !pkey[2] || !pkey[3] )
- return GCRYERR_BAD_MPI;
-
- pk.p = pkey[0];
- pk.q = pkey[1];
- pk.g = pkey[2];
- pk.y = pkey[3];
- if( !verify( data[0], data[1], hash, &pk ) )
- return GCRYERR_BAD_SIGNATURE;
- return 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ DSA_public_key pk;
+
+ if ((! data[0]) || (! data[1]) || (! hash)
+ || (! pkey[0]) || (! pkey[1]) || (! pkey[2]) || (! pkey[3]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ pk.p = pkey[0];
+ pk.q = pkey[1];
+ pk.g = pkey[2];
+ pk.y = pkey[3];
+ if (! verify (data[0], data[1], hash, &pk))
+ err = GPG_ERR_BAD_SIGNATURE;
+ }
+ return err;
}
-
unsigned int
-_gcry_dsa_get_nbits( int algo, MPI *pkey )
+_gcry_dsa_get_nbits (int algo, MPI *pkey)
{
- if( algo != GCRY_PK_DSA )
- return 0;
- return mpi_get_nbits( pkey[0] );
+ return mpi_get_nbits (pkey[0]);
}
static char *dsa_names[] =
diff --git a/cipher/elgamal.c b/cipher/elgamal.c
index e9a4804e..582533e4 100644
--- a/cipher/elgamal.c
+++ b/cipher/elgamal.c
@@ -30,45 +30,47 @@
#include "mpi.h"
#include "cipher.h"
-typedef struct {
- MPI p; /* prime */
- MPI g; /* group generator */
- MPI y; /* g^x mod p */
+typedef struct
+{
+ MPI p; /* prime */
+ MPI g; /* group generator */
+ MPI y; /* g^x mod p */
} ELG_public_key;
-typedef struct {
- MPI p; /* prime */
- MPI g; /* group generator */
- MPI y; /* g^x mod p */
- MPI x; /* secret exponent */
+typedef struct
+{
+ MPI p; /* prime */
+ MPI g; /* group generator */
+ MPI y; /* g^x mod p */
+ MPI x; /* secret exponent */
} ELG_secret_key;
-static void test_keys( ELG_secret_key *sk, unsigned nbits );
-static MPI gen_k( MPI p );
-static void generate( ELG_secret_key *sk, unsigned nbits, MPI **factors );
-static int check_secret_key( ELG_secret_key *sk );
-static void do_encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey );
-static void decrypt(MPI output, MPI a, MPI b, ELG_secret_key *skey );
-static void sign(MPI a, MPI b, MPI input, ELG_secret_key *skey);
-static int verify(MPI a, MPI b, MPI input, ELG_public_key *pkey);
+static void test_keys (ELG_secret_key *sk, unsigned nbits);
+static MPI gen_k (MPI p);
+static void generate (ELG_secret_key *sk, unsigned nbits, MPI **factors);
+static int check_secret_key (ELG_secret_key *sk);
+static void do_encrypt (MPI a, MPI b, MPI input, ELG_public_key *pkey);
+static void decrypt (MPI output, MPI a, MPI b, ELG_secret_key *skey);
+static void sign (MPI a, MPI b, MPI input, ELG_secret_key *skey);
+static int verify (MPI a, MPI b, MPI input, ELG_public_key *pkey);
-static void (*progress_cb) ( void *, const char *, int, int, int );
+static void (*progress_cb) (void *, const char *, int, int, int);
static void *progress_cb_data;
void
-_gcry_register_pk_elg_progress ( void (*cb)( void *,const char*, int,int,int),
- void *cb_data )
+_gcry_register_pk_elg_progress (void (*cb) (void *, const char *, int, int, int),
+ void *cb_data)
{
- progress_cb = cb;
- progress_cb_data = cb_data;
+ progress_cb = cb;
+ progress_cb_data = cb_data;
}
static void
-progress( int c )
+progress (int c)
{
if (progress_cb)
progress_cb (progress_cb_data, "pk_elg", c, 0, 0);
@@ -353,7 +355,7 @@ do_encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey )
*/
gcry_mpi_powm( b, pkey->y, k, pkey->p );
gcry_mpi_mulm( b, b, input, pkey->p );
- #if 0
+#if 0
if( DBG_CIPHER ) {
log_mpidump("elg encrypted y= ", pkey->y);
log_mpidump("elg encrypted p= ", pkey->p);
@@ -362,7 +364,7 @@ do_encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey )
log_mpidump("elg encrypted a= ", a);
log_mpidump("elg encrypted b= ", b);
}
- #endif
+#endif
mpi_free(k);
}
@@ -378,7 +380,7 @@ decrypt(MPI output, MPI a, MPI b, ELG_secret_key *skey )
gcry_mpi_powm( t1, a, skey->x, skey->p );
mpi_invm( t1, t1, skey->p );
mpi_mulm( output, b, t1, skey->p );
- #if 0
+#if 0
if( DBG_CIPHER ) {
log_mpidump("elg decrypted x= ", skey->x);
log_mpidump("elg decrypted p= ", skey->p);
@@ -386,7 +388,7 @@ decrypt(MPI output, MPI a, MPI b, ELG_secret_key *skey )
log_mpidump("elg decrypted b= ", b);
log_mpidump("elg decrypted M= ", output);
}
- #endif
+#endif
mpi_free(t1);
}
@@ -417,7 +419,7 @@ sign(MPI a, MPI b, MPI input, ELG_secret_key *skey )
mpi_invm(inv, k, p_1 );
mpi_mulm(b, t, inv, p_1 );
- #if 0
+#if 0
if( DBG_CIPHER ) {
log_mpidump("elg sign p= ", skey->p);
log_mpidump("elg sign g= ", skey->g);
@@ -428,7 +430,7 @@ sign(MPI a, MPI b, MPI input, ELG_secret_key *skey )
log_mpidump("elg sign a= ", a);
log_mpidump("elg sign b= ", b);
}
- #endif
+#endif
mpi_free(k);
mpi_free(t);
mpi_free(inv);
@@ -454,7 +456,7 @@ verify(MPI a, MPI b, MPI input, ELG_public_key *pkey )
t1 = mpi_alloc( mpi_get_nlimbs(a) );
t2 = mpi_alloc( mpi_get_nlimbs(a) );
- #if 0
+#if 0
/* t1 = (y^a mod p) * (a^b mod p) mod p */
gcry_mpi_powm( t1, pkey->y, a, pkey->p );
gcry_mpi_powm( t2, a, b, pkey->p );
@@ -464,7 +466,7 @@ verify(MPI a, MPI b, MPI input, ELG_public_key *pkey )
gcry_mpi_powm( t2, pkey->g, input, pkey->p );
rc = !mpi_cmp( t1, t2 );
- #elif 0
+#elif 0
/* t1 = (y^a mod p) * (a^b mod p) mod p */
base[0] = pkey->y; exp[0] = a;
base[1] = a; exp[1] = b;
@@ -475,7 +477,7 @@ verify(MPI a, MPI b, MPI input, ELG_public_key *pkey )
gcry_mpi_powm( t2, pkey->g, input, pkey->p );
rc = !mpi_cmp( t1, t2 );
- #else
+#else
/* t1 = g ^ - input * y ^ a * a ^ b mod p */
mpi_invm(t2, pkey->g, pkey->p );
base[0] = t2 ; exp[0] = input;
@@ -485,7 +487,7 @@ verify(MPI a, MPI b, MPI input, ELG_public_key *pkey )
mpi_mulpowm( t1, base, exp, pkey->p );
rc = !mpi_cmp_ui( t1, 1 );
- #endif
+#endif
mpi_free(t1);
mpi_free(t2);
@@ -496,133 +498,138 @@ verify(MPI a, MPI b, MPI input, ELG_public_key *pkey )
************** interface ******************
*********************************************/
-int
-_gcry_elg_generate( int algo, unsigned nbits, unsigned long dummy,
- MPI *skey, MPI **retfactors )
+gpg_err_code_t
+_gcry_elg_generate (int algo, unsigned nbits, unsigned long dummy,
+ MPI *skey, MPI **retfactors)
{
- ELG_secret_key sk;
-
- if( !is_ELGAMAL(algo) )
- return GCRYERR_INV_PK_ALGO;
-
- generate( &sk, nbits, retfactors );
- skey[0] = sk.p;
- skey[1] = sk.g;
- skey[2] = sk.y;
- skey[3] = sk.x;
- return 0;
+ ELG_secret_key sk;
+
+ generate (&sk, nbits, retfactors);
+ skey[0] = sk.p;
+ skey[1] = sk.g;
+ skey[2] = sk.y;
+ skey[3] = sk.x;
+
+ return GPG_ERR_NO_ERROR;
}
-int
-_gcry_elg_check_secret_key( int algo, MPI *skey )
+gpg_err_code_t
+_gcry_elg_check_secret_key (int algo, MPI *skey)
{
- ELG_secret_key sk;
-
- if( !is_ELGAMAL(algo) )
- return GCRYERR_INV_PK_ALGO;
- if( !skey[0] || !skey[1] || !skey[2] || !skey[3] )
- return GCRYERR_BAD_MPI;
-
- sk.p = skey[0];
- sk.g = skey[1];
- sk.y = skey[2];
- sk.x = skey[3];
- if( !check_secret_key( &sk ) )
- return GCRYERR_BAD_SECRET_KEY;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ ELG_secret_key sk;
+
+ if ((! skey[0]) || (! skey[1]) || (! skey[2]) || (! skey[3]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ sk.p = skey[0];
+ sk.g = skey[1];
+ sk.y = skey[2];
+ sk.x = skey[3];
+
+ if (! check_secret_key (&sk))
+ err = GPG_ERR_BAD_SECKEY;
+ }
- return 0;
+ return err;
}
-
-int
-_gcry_elg_encrypt( int algo, MPI *resarr, MPI data, MPI *pkey, int flags)
+gpg_err_code_t
+_gcry_elg_encrypt (int algo, MPI *resarr, MPI data, MPI *pkey, int flags)
{
- ELG_public_key pk;
-
- if( !is_ELGAMAL(algo) )
- return GCRYERR_INV_PK_ALGO;
- if( !data || !pkey[0] || !pkey[1] || !pkey[2] )
- return GCRYERR_BAD_MPI;
-
- pk.p = pkey[0];
- pk.g = pkey[1];
- pk.y = pkey[2];
- resarr[0] = mpi_alloc( mpi_get_nlimbs( pk.p ) );
- resarr[1] = mpi_alloc( mpi_get_nlimbs( pk.p ) );
- do_encrypt( resarr[0], resarr[1], data, &pk );
- return 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ ELG_public_key pk;
+
+ if ((! data) || (! pkey[0]) || (! pkey[1]) || (! pkey[2]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ pk.p = pkey[0];
+ pk.g = pkey[1];
+ pk.y = pkey[2];
+ resarr[0] = mpi_alloc (mpi_get_nlimbs (pk.p));
+ resarr[1] = mpi_alloc (mpi_get_nlimbs (pk.p));
+ do_encrypt (resarr[0], resarr[1], data, &pk);
+ }
+ return err;
}
-int
-_gcry_elg_decrypt( int algo, MPI *result, MPI *data, MPI *skey, int flags)
+
+gpg_err_code_t
+_gcry_elg_decrypt (int algo, MPI *result, MPI *data, MPI *skey, int flags)
{
- ELG_secret_key sk;
-
- if( !is_ELGAMAL(algo) )
- return GCRYERR_INV_PK_ALGO;
- if( !data[0] || !data[1]
- || !skey[0] || !skey[1] || !skey[2] || !skey[3] )
- return GCRYERR_BAD_MPI;
-
- sk.p = skey[0];
- sk.g = skey[1];
- sk.y = skey[2];
- sk.x = skey[3];
- *result = mpi_alloc_secure( mpi_get_nlimbs( sk.p ) );
- decrypt( *result, data[0], data[1], &sk );
- return 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ ELG_secret_key sk;
+
+ if ((! data[0]) || (! data[1])
+ || (! skey[0]) || (! skey[1]) || (! skey[2]) || (! skey[3]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ sk.p = skey[0];
+ sk.g = skey[1];
+ sk.y = skey[2];
+ sk.x = skey[3];
+ *result = mpi_alloc_secure (mpi_get_nlimbs (sk.p));
+ decrypt (*result, data[0], data[1], &sk);
+ }
+ return err;
}
-int
-_gcry_elg_sign( int algo, MPI *resarr, MPI data, MPI *skey )
+
+gpg_err_code_t
+_gcry_elg_sign (int algo, MPI *resarr, MPI data, MPI *skey)
{
- ELG_secret_key sk;
-
- if( !is_ELGAMAL(algo) )
- return GCRYERR_INV_PK_ALGO;
- if( !data || !skey[0] || !skey[1] || !skey[2] || !skey[3] )
- return GCRYERR_BAD_MPI;
-
- sk.p = skey[0];
- sk.g = skey[1];
- sk.y = skey[2];
- sk.x = skey[3];
- resarr[0] = mpi_alloc( mpi_get_nlimbs( sk.p ) );
- resarr[1] = mpi_alloc( mpi_get_nlimbs( sk.p ) );
- sign( resarr[0], resarr[1], data, &sk );
- return 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ ELG_secret_key sk;
+
+ if ((! data)
+ || (! skey[0]) || (! skey[1]) || (! skey[2]) || (! skey[3]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ sk.p = skey[0];
+ sk.g = skey[1];
+ sk.y = skey[2];
+ sk.x = skey[3];
+ resarr[0] = mpi_alloc (mpi_get_nlimbs (sk.p));
+ resarr[1] = mpi_alloc (mpi_get_nlimbs (sk.p));
+ sign (resarr[0], resarr[1], data, &sk);
+ }
+
+ return err;
}
-int
-_gcry_elg_verify( int algo, MPI hash, MPI *data, MPI *pkey,
- int (*cmp)(void *, MPI), void *opaquev )
+gpg_err_code_t
+_gcry_elg_verify (int algo, MPI hash, MPI *data, MPI *pkey,
+ int (*cmp) (void *, MPI), void *opaquev)
{
- ELG_public_key pk;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ ELG_public_key pk;
+
+ if ((! data[0]) || (! data[1]) || (! hash)
+ || (! pkey[0]) || (! pkey[1]) || (! pkey[2]))
+ err = GPG_ERR_BAD_MPI;
+ else
+ {
+ pk.p = pkey[0];
+ pk.g = pkey[1];
+ pk.y = pkey[2];
+ if (! verify (data[0], data[1], hash, &pk))
+ err = GPG_ERR_BAD_SIGNATURE;
+ }
- if( !is_ELGAMAL(algo) )
- return GCRYERR_INV_PK_ALGO;
- if( !data[0] || !data[1] || !hash
- || !pkey[0] || !pkey[1] || !pkey[2] )
- return GCRYERR_BAD_MPI;
-
- pk.p = pkey[0];
- pk.g = pkey[1];
- pk.y = pkey[2];
- if( !verify( data[0], data[1], hash, &pk ) )
- return GCRYERR_BAD_SIGNATURE;
- return 0;
+ return err;
}
-
unsigned int
-_gcry_elg_get_nbits( int algo, MPI *pkey )
+_gcry_elg_get_nbits (int algo, MPI *pkey)
{
- if( !is_ELGAMAL(algo) )
- return 0;
- return mpi_get_nbits( pkey[0] );
+ return mpi_get_nbits (pkey[0]);
}
static char *elg_names[] =
diff --git a/cipher/md.c b/cipher/md.c
index 1d0f9f9f..08bc06da 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -125,7 +125,8 @@ static int default_digests_registered;
static void
gcry_digest_register_default (void)
{
- int i, err = 0;
+ gpg_err_code_t err = 0;
+ int i;
for (i = 0; (! err) && digest_table[i].digest; i++)
err = _gcry_module_add (&digests_registered,
@@ -197,16 +198,17 @@ gcry_digest_id_new (void)
/* Public function. Register a provided DIGEST. Returns zero on
success, in which case the chosen digest ID has been stored in
DIGEST, or an error code. */
-int
+gpg_error_t
gcry_digest_register (GcryDigestSpec *digest, GcryModule **module)
{
- int id, err = 0;
+ gpg_err_code_t err = 0;
+ int id;
GcryModule *mod;
ath_mutex_lock (&digests_registered_lock);
id = gcry_digest_id_new ();
if (! id)
- err = GCRYERR_INTERNAL; /* FIXME. */
+ err = GPG_ERR_INTERNAL; /* FIXME. */
else
{
digest->id = id;
@@ -218,7 +220,7 @@ gcry_digest_register (GcryDigestSpec *digest, GcryModule **module)
if (! err)
*module = mod;
- return err;
+ return gpg_error (err);
}
/* Public function. Unregister the digest identified by ID, which
@@ -239,7 +241,7 @@ typedef struct gcry_md_list
PROPERLY_ALIGNED_TYPE context;
} GcryDigestEntry;
-/* this structure is put right after the GCRY_MD_HD buffer, so that
+/* this structure is put right after the gcry_md_hd_t buffer, so that
* only one memory block is needed. */
struct gcry_md_context
{
@@ -255,19 +257,19 @@ struct gcry_md_context
#define CTX_MAGIC_SECURE 0x16917011
static const char * digest_algo_to_string( int algo );
-static int check_digest_algo( int algo );
-static GCRY_MD_HD md_open( int algo, int secure, int hmac );
-static int md_enable( GCRY_MD_HD hd, int algo );
-static GCRY_MD_HD md_copy( GCRY_MD_HD a );
-static void md_close(GCRY_MD_HD a);
-static void md_write( GCRY_MD_HD a, byte *inbuf, size_t inlen);
-static void md_final(GCRY_MD_HD a);
-static byte *md_read( GCRY_MD_HD a, int algo );
-static int md_get_algo( GCRY_MD_HD a );
+static gpg_err_code_t check_digest_algo (int algo);
+static gpg_err_code_t md_open (gcry_md_hd_t *h, int algo, int secure, int hmac);
+static gpg_err_code_t md_enable (gcry_md_hd_t hd, int algo);
+static gpg_err_code_t md_copy (gcry_md_hd_t a, gcry_md_hd_t *b);
+static void md_close (gcry_md_hd_t a);
+static void md_write (gcry_md_hd_t a, byte *inbuf, size_t inlen);
+static void md_final(gcry_md_hd_t a);
+static byte *md_read( gcry_md_hd_t a, int algo );
+static int md_get_algo( gcry_md_hd_t a );
static int md_digest_length( int algo );
static const byte *md_asn_oid( int algo, size_t *asnlen, size_t *mdlen );
-static void md_start_debug( GCRY_MD_HD a, const char *suffix );
-static void md_stop_debug( GCRY_MD_HD a );
+static void md_start_debug( gcry_md_hd_t a, const char *suffix );
+static void md_stop_debug( gcry_md_hd_t a );
/****************
* Map a string to the digest algo
@@ -351,10 +353,10 @@ gcry_md_algo_name (int id)
}
-static int
+static gpg_err_code_t
check_digest_algo (int id)
{
- int rc = 0;
+ gpg_err_code_t rc = 0;
GcryModule *digest;
REGISTER_DEFAULT_DIGESTS;
@@ -364,7 +366,7 @@ check_digest_algo (int id)
if (digest)
_gcry_module_release (digest);
else
- rc = GCRYERR_INV_MD_ALGO;
+ rc = GPG_ERR_DIGEST_ALGO;
ath_mutex_unlock (&digests_registered_lock);
return rc;
@@ -377,12 +379,13 @@ check_digest_algo (int id)
* More algorithms may be added by md_enable(). The initial algorithm
* may be 0.
*/
-static GCRY_MD_HD
-md_open( int algo, int secure, int hmac )
+static gpg_err_code_t
+md_open (gcry_md_hd_t *h, int algo, int secure, int hmac)
{
- GCRY_MD_HD hd;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ int bufsize = secure ? 512 : 1024;
struct gcry_md_context *ctx;
- int bufsize = secure? 512 : 1024;
+ gcry_md_hd_t hd;
size_t n;
/* Allocate a memory area to hold the caller visible buffer with it's
@@ -399,75 +402,97 @@ md_open( int algo, int secure, int hmac )
*
* We have to make sture that private is well aligned.
*/
- n = sizeof( struct gcry_md_handle ) + bufsize;
- n = ((n + sizeof(PROPERLY_ALIGNED_TYPE)-1)
- / sizeof(PROPERLY_ALIGNED_TYPE) ) * sizeof(PROPERLY_ALIGNED_TYPE);
+ n = sizeof (struct gcry_md_handle) + bufsize;
+ n = ((n + sizeof (PROPERLY_ALIGNED_TYPE) - 1)
+ / sizeof (PROPERLY_ALIGNED_TYPE)) * sizeof (PROPERLY_ALIGNED_TYPE);
/* allocate and set the Context pointer to the private data */
- hd = secure ? gcry_malloc_secure( n + sizeof( struct gcry_md_context ) )
- : gcry_malloc( n + sizeof( struct gcry_md_context ) );
- if( !hd ) {
- set_lasterr( GCRYERR_NO_MEM );
- return NULL;
- }
+ if (secure)
+ hd = gcry_malloc_secure (n + sizeof (struct gcry_md_context));
+ else
+ hd = gcry_malloc (n + sizeof (struct gcry_md_context));
+
+ if (! hd)
+ err = gpg_err_code_from_errno (errno);
- hd->ctx = ctx = (struct gcry_md_context*)( (char*)hd + n );
- /* setup the globally visible data (bctl in the diagram)*/
- hd->bufsize = n - sizeof( struct gcry_md_handle ) + 1;
- hd->bufpos = 0;
- /* initialize the private data */
- memset( hd->ctx, 0, sizeof *hd->ctx );
- ctx->magic = secure ? CTX_MAGIC_SECURE : CTX_MAGIC_NORMAL;
- ctx->secure = secure;
- if( hmac ) {
- ctx->macpads = gcry_malloc_secure( 128 );
- if( !ctx->macpads ) {
- md_close( hd );
- set_lasterr( GCRYERR_NO_MEM );
- return NULL;
+ if (! err)
+ {
+ hd->ctx = ctx = (struct gcry_md_context *) ((char *) hd + n);
+ /* setup the globally visible data (bctl in the diagram)*/
+ hd->bufsize = n - sizeof (struct gcry_md_handle) + 1;
+ hd->bufpos = 0;
+
+ /* initialize the private data */
+ memset (hd->ctx, 0, sizeof *hd->ctx);
+ ctx->magic = secure ? CTX_MAGIC_SECURE : CTX_MAGIC_NORMAL;
+ ctx->secure = secure;
+
+ if (hmac)
+ {
+ ctx->macpads = gcry_malloc_secure (128);
+ if (! ctx->macpads)
+ {
+ md_close (hd);
+ err = gpg_err_code_from_errno (errno);
+ }
+ }
}
- }
- fast_random_poll(); /* FIXME: should we really do that? */
- if( algo && md_enable( hd, algo ) ) {
- md_close( hd );
- return NULL;
- }
- return hd;
-}
+ if (! err)
+ {
+ /* FIXME: should we really do that? */
+ fast_random_poll ();
+
+ if (algo)
+ {
+ err = md_enable (hd, algo);
+ if (err)
+ md_close (hd);
+ }
+ }
+
+ if (! err)
+ *h = hd;
+
+ return err;
+}
/* Create a message digest object for algorithm ALGO. FLAGS may be
given as an bitwise OR of the gcry_md_flags values. ALGO may be
given as 0 if the algorithms to be used are later set using
gcry_md_enable. */
-GcryMDHd
-gcry_md_open (int algo, unsigned int flags)
+gpg_error_t
+gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags)
{
- GCRY_MD_HD hd;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ gcry_md_hd_t hd;
if ((flags & ~(GCRY_MD_FLAG_SECURE | GCRY_MD_FLAG_HMAC)))
+ err = GPG_ERR_INV_ARG;
+ else
{
- set_lasterr (GCRYERR_INV_ARG);
- return NULL;
+ err = md_open (&hd, algo, (flags & GCRY_MD_FLAG_SECURE),
+ (flags & GCRY_MD_FLAG_HMAC));
+ if (! err)
+ *h = hd;
}
- hd = md_open (algo, (flags & GCRY_MD_FLAG_SECURE),
- (flags & GCRY_MD_FLAG_HMAC));
- return hd;
+ return gpg_error (err);
}
-static int
-md_enable (GCRY_MD_HD hd, int id)
+static gpg_err_code_t
+md_enable (gcry_md_hd_t hd, int id)
{
struct gcry_md_context *h = hd->ctx;
- GcryDigestSpec *digest;
+ GcryDigestSpec *digest = NULL;
GcryDigestEntry *entry;
GcryModule *module;
+ gpg_err_code_t err = 0;
for (entry = h->list; entry; entry = entry->next)
if (entry->digest->id == id)
- return 0; /* already enabled */
+ return err; /* already enabled */
REGISTER_DEFAULT_DIGESTS;
@@ -477,109 +502,143 @@ md_enable (GCRY_MD_HD hd, int id)
if (! module)
{
log_debug ("md_enable: algorithm %d not available\n", id);
- return set_lasterr (GCRYERR_INV_MD_ALGO);
+ err = GPG_ERR_DIGEST_ALGO;
}
+ else
+ digest = (GcryDigestSpec *) module->spec;
- digest = (GcryDigestSpec *) module->spec;
+ if (! err)
+ {
+ size_t size = sizeof (*entry)
+ + digest->contextsize
+ - sizeof (entry->context);
+
+ /* and allocate a new list entry */
+ if (h->secure)
+ entry = gcry_malloc_secure (size);
+ else
+ entry = gcry_malloc (size);
+
+ if (! entry)
+ err = gpg_err_code_from_errno (errno);
+ else
+ {
+ entry->digest = digest;
+ entry->module = module;
+ entry->next = h->list;
+ h->list = entry;
- /* and allocate a new list entry */
- entry = h->secure
- ? gcry_malloc_secure (sizeof (*entry)
- + digest->contextsize
- - sizeof (entry->context))
- : gcry_malloc (sizeof (*entry)
- + digest->contextsize
- - sizeof (entry->context));
+ /* and init this instance */
+ (*entry->digest->init) (&entry->context.c);
+ }
+ }
- if (! entry)
- return set_lasterr (GCRYERR_NO_MEM);
+ if (err)
+ {
+ if (module)
+ {
+ ath_mutex_lock (&digests_registered_lock);
+ _gcry_module_release (module);
+ ath_mutex_unlock (&digests_registered_lock);
+ }
+ }
- entry->digest = digest;
- entry->module = module;
- entry->next = h->list;
- h->list = entry;
-
- /* and init this instance */
- (*entry->digest->init) (&entry->context.c);
- return 0;
+ return err;
}
-int
-gcry_md_enable (GCRY_MD_HD hd, int id)
+gpg_error_t
+gcry_md_enable (gcry_md_hd_t hd, int id)
{
- return md_enable ( hd, id);
+ gpg_err_code_t err = md_enable (hd, id);
+ return gpg_error (err);
}
-static GCRY_MD_HD
-md_copy (GCRY_MD_HD ahd)
+static gpg_err_code_t
+md_copy (gcry_md_hd_t ahd, gcry_md_hd_t *b_hd)
{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
struct gcry_md_context *a = ahd->ctx;
struct gcry_md_context *b;
- GCRY_MD_HD bhd;
GcryDigestEntry *ar, *br;
+ gcry_md_hd_t bhd;
size_t n;
if (ahd->bufpos)
md_write (ahd, NULL, 0);
n = (char *) ahd->ctx - (char *) ahd;
- bhd = a->secure
- ? gcry_malloc_secure (n + sizeof (struct gcry_md_context))
- : gcry_malloc (n + sizeof (struct gcry_md_context));
+ if (a->secure)
+ bhd = gcry_malloc_secure (n + sizeof (struct gcry_md_context));
+ else
+ bhd = gcry_malloc (n + sizeof (struct gcry_md_context));
if (! bhd)
- {
- set_lasterr (GCRYERR_NO_MEM);
- return NULL;
- }
+ err = gpg_err_code_from_errno (errno);
- bhd->ctx = b = (struct gcry_md_context *) ((char *) bhd + n);
- /* no need to copy the buffer due to the write above */
- assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1));
- bhd->bufsize = ahd->bufsize;
- bhd->bufpos = 0;
- assert (! ahd->bufpos);
- memcpy (b, a, sizeof *a);
- b->list = NULL;
- b->debug = NULL;
- if (a->macpads)
+ if (! err)
{
- b->macpads = gcry_malloc_secure (128);
- memcpy (b->macpads, a->macpads, 128);
+ bhd->ctx = b = (struct gcry_md_context *) ((char *) bhd + n);
+ /* no need to copy the buffer due to the write above */
+ assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1));
+ bhd->bufsize = ahd->bufsize;
+ bhd->bufpos = 0;
+ assert (! ahd->bufpos);
+ memcpy (b, a, sizeof *a);
+ b->list = NULL;
+ b->debug = NULL;
+ if (a->macpads)
+ {
+ b->macpads = gcry_malloc_secure (128);
+ if (! b->macpads)
+ {
+ md_close (bhd);
+ err = gpg_err_code_from_errno (errno);
+ }
+ else
+ memcpy (b->macpads, a->macpads, 128);
+ }
}
/* and now copy the complete list of algorithms */
/* I know that the copied list is reversed, but that doesn't matter */
- for (ar = a->list; ar; ar = ar->next)
- {
- br = a->secure
- ? gcry_xmalloc_secure (sizeof *br
- + ar->digest->contextsize
- - sizeof(ar->context))
- : gcry_xmalloc (sizeof *br
- + ar->digest->contextsize
- - sizeof (ar->context));
- memcpy (br, ar,
- sizeof (*br) + ar->digest->contextsize - sizeof (ar->context));
- br->next = b->list;
- b->list = br;
-
- /* Add a reference to the module. */
- ath_mutex_lock (&digests_registered_lock);
- _gcry_module_use (br->module);
- ath_mutex_unlock (&digests_registered_lock);
- }
+
+ if (! err)
+ for (ar = a->list; ar; ar = ar->next)
+ {
+ if (a->secure)
+ br = gcry_xmalloc_secure (sizeof *br
+ + ar->digest->contextsize
+ - sizeof(ar->context));
+ else
+ br = gcry_xmalloc (sizeof *br
+ + ar->digest->contextsize
+ - sizeof (ar->context));
+ memcpy (br, ar,
+ sizeof (*br) + ar->digest->contextsize - sizeof (ar->context));
+ br->next = b->list;
+ b->list = br;
+
+ /* Add a reference to the module. */
+ ath_mutex_lock (&digests_registered_lock);
+ _gcry_module_use (br->module);
+ ath_mutex_unlock (&digests_registered_lock);
+ }
if (a->debug)
- md_start_debug( bhd, "unknown" );
- return bhd;
+ md_start_debug (bhd, "unknown");
+
+ if (! err)
+ *b_hd = bhd;
+
+ return err;
}
-GCRY_MD_HD
-gcry_md_copy (GCRY_MD_HD hd)
+gpg_error_t
+gcry_md_copy (gcry_md_hd_t hd, gcry_md_hd_t *handle)
{
- return md_copy (hd);
+ gpg_err_code_t err = md_copy (hd, handle);
+ return gpg_error (err);
}
/****************
@@ -587,7 +646,7 @@ gcry_md_copy (GCRY_MD_HD hd)
* instead of a md_close(); md_open().
*/
void
-gcry_md_reset (GCRY_MD_HD a)
+gcry_md_reset (gcry_md_hd_t a)
{
GcryDigestEntry *r;
@@ -603,7 +662,7 @@ gcry_md_reset (GCRY_MD_HD a)
}
static void
-md_close (GCRY_MD_HD a)
+md_close (gcry_md_hd_t a)
{
GcryDigestEntry *r, *r2;
@@ -624,13 +683,13 @@ md_close (GCRY_MD_HD a)
}
void
-gcry_md_close (GCRY_MD_HD hd)
+gcry_md_close (gcry_md_hd_t hd)
{
md_close (hd);
}
static void
-md_write (GCRY_MD_HD a, byte *inbuf, size_t inlen)
+md_write (gcry_md_hd_t a, byte *inbuf, size_t inlen)
{
GcryDigestEntry *r;
@@ -652,13 +711,13 @@ md_write (GCRY_MD_HD a, byte *inbuf, size_t inlen)
}
void
-gcry_md_write (GCRY_MD_HD hd, const void *inbuf, size_t inlen)
+gcry_md_write (gcry_md_hd_t hd, const void *inbuf, size_t inlen)
{
md_write (hd, (unsigned char *) inbuf, inlen);
}
static void
-md_final (GCRY_MD_HD a)
+md_final (gcry_md_hd_t a)
{
GcryDigestEntry *r;
@@ -679,10 +738,11 @@ md_final (GCRY_MD_HD a)
int algo = md_get_algo (a);
byte *p = md_read (a, algo);
size_t dlen = md_digest_length (algo);
+ gcry_md_hd_t om;
+ gpg_err_code_t err = md_open (&om, algo, a->ctx->secure, 0);
- GCRY_MD_HD om = md_open (algo, a->ctx->secure, 0);
- if (! om)
- _gcry_fatal_error (gcry_errno (), NULL);
+ if (err)
+ _gcry_fatal_error (err, NULL);
md_write (om, a->ctx->macpads+64, 64);
md_write (om, p, dlen);
md_final (om);
@@ -692,8 +752,8 @@ md_final (GCRY_MD_HD a)
}
}
-static int
-prepare_macpads( GCRY_MD_HD hd, const byte *key, size_t keylen)
+static gpg_err_code_t
+prepare_macpads( gcry_md_hd_t hd, const byte *key, size_t keylen)
{
int i;
int algo = md_get_algo( hd );
@@ -701,12 +761,12 @@ prepare_macpads( GCRY_MD_HD hd, const byte *key, size_t keylen)
byte *ipad, *opad;
if( !algo )
- return GCRYERR_INV_MD_ALGO; /* i.e. no algo enabled */
+ return GPG_ERR_DIGEST_ALGO; /* i.e. no algo enabled */
if( keylen > 64 ) {
helpkey = gcry_malloc_secure( md_digest_length( algo ) );
if( !helpkey )
- return GCRYERR_NO_MEM;
+ return gpg_err_code_from_errno (errno);
gcry_md_hash_buffer( algo, helpkey, key, keylen );
key = helpkey;
keylen = md_digest_length( algo );
@@ -723,13 +783,14 @@ prepare_macpads( GCRY_MD_HD hd, const byte *key, size_t keylen)
opad[i] ^= 0x5c;
}
gcry_free( helpkey );
- return 0;
+
+ return GPG_ERR_NO_ERROR;
}
-int
-gcry_md_ctl (GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen)
+gpg_error_t
+gcry_md_ctl (gcry_md_hd_t hd, int cmd, byte *buffer, size_t buflen)
{
- int rc = 0;
+ gpg_err_code_t rc = 0;
switch (cmd)
{
@@ -737,7 +798,7 @@ gcry_md_ctl (GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen)
md_final (hd);
break;
case GCRYCTL_SET_KEY:
- rc = gcry_md_setkey (hd, buffer, buflen);
+ rc = gpg_err_code (gcry_md_setkey (hd, buffer, buflen));
break;
case GCRYCTL_START_DUMP:
md_start_debug (hd, buffer);
@@ -746,22 +807,26 @@ gcry_md_ctl (GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen)
md_stop_debug( hd );
break;
default:
- rc = GCRYERR_INV_OP;
+ rc = GPG_ERR_INV_OP;
}
- return set_lasterr( rc );
+ return gpg_error (rc);
}
-int
-gcry_md_setkey( GCRY_MD_HD hd, const void *key, size_t keylen )
- {
- int rc = 0;
+gpg_error_t
+gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen)
+{
+ gpg_err_code_t rc = GPG_ERR_NO_ERROR;
- if( !(hd->ctx->macpads ) )
- rc = GCRYERR_CONFLICT;
- else if ( !(rc = prepare_macpads( hd, key, keylen )) )
- gcry_md_reset( hd );
+ if (! hd->ctx->macpads)
+ rc = GPG_ERR_CONFLICT;
+ else
+ {
+ rc = prepare_macpads (hd, key, keylen);
+ if (! rc)
+ gcry_md_reset (hd);
+ }
- return rc;
+ return gpg_error (rc);
}
@@ -769,7 +834,7 @@ gcry_md_setkey( GCRY_MD_HD hd, const void *key, size_t keylen )
* if ALGO is null get the digest for the used algo (which should be only one)
*/
static byte *
-md_read( GCRY_MD_HD a, int algo )
+md_read( gcry_md_hd_t a, int algo )
{
GcryDigestEntry *r = a->ctx->list;
@@ -795,7 +860,7 @@ md_read( GCRY_MD_HD a, int algo )
* the hash.
*/
byte *
-gcry_md_read (GCRY_MD_HD hd, int algo)
+gcry_md_read (gcry_md_hd_t hd, int algo)
{
gcry_md_ctl (hd, GCRYCTL_FINALIZE, NULL, 0);
return md_read (hd, algo);
@@ -812,7 +877,7 @@ gcry_md_read (GCRY_MD_HD hd, int algo)
*/
#if 0
static int
-md_digest( GCRY_MD_HD a, int algo, byte *buffer, int buflen )
+md_digest( gcry_md_hd_t a, int algo, byte *buffer, int buflen )
{
struct md_digest_list_s *r = NULL;
char *context;
@@ -856,11 +921,11 @@ md_digest( GCRY_MD_HD a, int algo, byte *buffer, int buflen )
/****************
* Read out an intermediate digest.
*/
-int
-gcry_md_get (GCRY_MD_HD hd, int algo, byte *buffer, int buflen)
+gpg_err_code_t
+gcry_md_get (gcry_md_hd_t hd, int algo, byte *buffer, int buflen)
{
/*md_digest ... */
- return GCRYERR_INTERNAL;
+ return GPG_ERR_INTERNAL;
}
@@ -879,9 +944,10 @@ gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length)
{
/* for the others we do not have a fast function, so we use the
normal functions to do it */
-
- GCRY_MD_HD h = md_open (algo, 0, 0);
- if( !h )
+ gcry_md_hd_t h;
+ gpg_err_code_t err = md_open (&h, algo, 0, 0);
+ if(! err)
+ /* FIXME? */
BUG(); /* algo not available */
md_write (h, (byte *) buffer, length);
md_final (h);
@@ -891,26 +957,25 @@ gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length)
}
static int
-md_get_algo (GCRY_MD_HD a)
+md_get_algo (gcry_md_hd_t a)
{
GcryDigestEntry *r = a->ctx->list;
if (r && r->next)
log_error("WARNING: more than algorithm in md_get_algo()\n");
- return r->digest->id;
+ return r ? r->digest->id : 0;
}
-
-int
-gcry_md_get_algo (GCRY_MD_HD hd)
+gpg_error_t
+gcry_md_get_algo (gcry_md_hd_t hd, int *id)
{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
int algo = md_get_algo (hd);
- if (!algo)
- {
- set_lasterr (GCRYERR_GENERAL);
- return 0;
- }
- return algo;
+ if (! algo)
+ err = GPG_ERR_GENERAL; /* FIXME? */
+ else
+ *id = algo;
+ return gpg_error (err);
}
@@ -988,58 +1053,57 @@ md_asn_oid (int id, size_t *asnlen, size_t *mdlen)
* Return the ASNOID of the algorithm in buffer. if buffer is NULL, only
* the required length is returned.
*
- * On error the value -1 is returned and the error reason may be
- * retrieved by gcry_errno().
* Note: Because this function is in most cases used to return an
* integer value, we can make it easier for the caller to just look at
* the return value. The caller will in all cases consult the value
* and thereby detecting whether a error occured or not (i.e. while checking
* the block size)
*/
-int
-gcry_md_algo_info( int algo, int what, void *buffer, size_t *nbytes)
+gpg_error_t
+gcry_md_algo_info (int algo, int what, void *buffer, size_t *nbytes)
{
- switch( what ) {
- case GCRYCTL_TEST_ALGO:
- if( buffer || nbytes ) {
- set_lasterr( GCRYERR_INV_ARG );
- return -1;
- }
- if( check_digest_algo( algo ) ) {
- set_lasterr( GCRYERR_INV_MD_ALGO );
- return -1;
- }
- break;
-
- case GCRYCTL_GET_ASNOID: {
- size_t asnlen;
- const char *asn = md_asn_oid( algo, &asnlen, NULL );
- if( buffer && *nbytes >= asnlen ) {
- memcpy( buffer, asn, asnlen );
- *nbytes = asnlen;
- return 0;
- }
- if( !buffer && nbytes ) {
- *nbytes = asnlen;
- return 0;
- }
- set_lasterr( buffer ? GCRYERR_TOO_SHORT : GCRYERR_INV_ARG );
- return -1;
- }
- break;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
+ switch (what)
+ {
+ case GCRYCTL_TEST_ALGO:
+ if (buffer || nbytes)
+ err = GPG_ERR_INV_ARG;
+ else
+ err = check_digest_algo (algo);
+ break;
+
+ case GCRYCTL_GET_ASNOID:
+ {
+ size_t asnlen;
+ const char *asn = md_asn_oid (algo, &asnlen, NULL);
+ if (buffer && (*nbytes >= asnlen))
+ {
+ memcpy (buffer, asn, asnlen);
+ *nbytes = asnlen;
+ }
+ else if ((! buffer) && nbytes)
+ *nbytes = asnlen;
+ else
+ {
+ if (buffer)
+ err = GPG_ERR_TOO_SHORT;
+ else
+ err = GPG_ERR_INV_ARG;
+ }
+ break;
+ }
default:
- set_lasterr( GCRYERR_INV_OP );
- return -1;
+ err = GPG_ERR_INV_OP;
}
- return 0;
-}
-
+ return gpg_error (err);
+}
static void
-md_start_debug( GCRY_MD_HD md, const char *suffix )
+md_start_debug( gcry_md_hd_t md, const char *suffix )
{
static int idx=0;
char buf[25];
@@ -1056,7 +1120,7 @@ md_start_debug( GCRY_MD_HD md, const char *suffix )
}
static void
-md_stop_debug( GCRY_MD_HD md )
+md_stop_debug( gcry_md_hd_t md )
{
if( md->ctx->debug ) {
if( md->bufpos )
@@ -1085,35 +1149,43 @@ md_stop_debug( GCRY_MD_HD md )
* Returns 1 if the algo is enanled for that handle.
* The algo must be passed as the address of an int.
*/
-int
-gcry_md_info( GCRY_MD_HD h, int cmd, void *buffer, size_t *nbytes)
+gpg_error_t
+gcry_md_info (gcry_md_hd_t h, int cmd, void *buffer, size_t *nbytes)
{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
- switch( cmd ) {
- case GCRYCTL_IS_SECURE:
- return h->ctx->secure;
-
- case GCRYCTL_IS_ALGO_ENABLED:
+ switch (cmd)
{
- int algo;
- GcryDigestEntry *r;
-
- if (!buffer || (nbytes && *nbytes != sizeof (int))) {
- set_lasterr (GCRYERR_INV_ARG);
- return -1;
- }
- algo = *(int*)buffer;
+ case GCRYCTL_IS_SECURE:
+ *nbytes = h->ctx->secure;
+ break;
- for(r=h->ctx->list; r; r = r->next ) {
- if( r->digest->id == algo )
- return 1;
+ case GCRYCTL_IS_ALGO_ENABLED:
+ {
+ GcryDigestEntry *r;
+ int algo;
+
+ if ((! buffer) || (nbytes && (*nbytes != sizeof (int))))
+ err = GPG_ERR_INV_ARG;
+ else
+ {
+ algo = *(int*)buffer;
+
+ *nbytes = 0;
+ for(r=h->ctx->list; r; r = r->next ) {
+ if (r->digest->id == algo)
+ {
+ *nbytes = 1;
+ break;
+ }
+ }
+ }
+ break;
}
- }
- break;
default:
- set_lasterr( GCRYERR_INV_OP );
- return -1;
+ err = GPG_ERR_INV_OP;
}
- return 0;
+
+ return gpg_error (err);
}
diff --git a/cipher/md4.c b/cipher/md4.c
index 0135e345..db992aad 100644
--- a/cipher/md4.c
+++ b/cipher/md4.c
@@ -278,17 +278,17 @@ md4_final( void *context )
_gcry_burn_stack (80+6*sizeof(void*));
p = hd->buf;
- #ifdef BIG_ENDIAN_HOST
- #define X(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
+#ifdef BIG_ENDIAN_HOST
+#define X(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
*p++ = hd->a >> 16; *p++ = hd->a >> 24; } while(0)
- #else /* little endian */
- #define X(a) do { *(u32*)p = (*hd).a ; p += 4; } while(0)
- #endif
+#else /* little endian */
+#define X(a) do { *(u32*)p = (*hd).a ; p += 4; } while(0)
+#endif
X(A);
X(B);
X(C);
X(D);
- #undef X
+#undef X
}
diff --git a/cipher/md5.c b/cipher/md5.c
index 248df681..73915fdc 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -303,17 +303,17 @@ md5_final( void *context)
_gcry_burn_stack (80+6*sizeof(void*));
p = hd->buf;
- #ifdef BIG_ENDIAN_HOST
- #define X(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
+#ifdef BIG_ENDIAN_HOST
+#define X(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
*p++ = hd->a >> 16; *p++ = hd->a >> 24; } while(0)
- #else /* little endian */
- #define X(a) do { *(u32*)p = (*hd).a ; p += 4; } while(0)
- #endif
+#else /* little endian */
+#define X(a) do { *(u32*)p = (*hd).a ; p += 4; } while(0)
+#endif
X(A);
X(B);
X(C);
X(D);
- #undef X
+#undef X
}
diff --git a/cipher/primegen.c b/cipher/primegen.c
index f2ece0e4..eb6e1e42 100644
--- a/cipher/primegen.c
+++ b/cipher/primegen.c
@@ -346,7 +346,7 @@ _gcry_generate_elg_prime( int mode, unsigned pbits, unsigned qbits,
log_debug("checking g: ");
/*mpi_print( stderr, g, 1 );*/
#if __GNUC__ >= 2
-# warning we need an internal mpi_print for debugging
+#warning we need an internal mpi_print for debugging
#endif
}
else
diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index 5ee00d73..6de6eb23 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -30,12 +30,10 @@
#include "cipher.h"
#include "ath.h"
-/* FIXME: use set_lasterr() */
-
-static int pubkey_decrypt (int algo, MPI *result, MPI *data, MPI *skey, int flags);
-static int pubkey_sign (int algo, MPI *resarr, MPI hash, MPI *skey);
-static int pubkey_verify (int algo, MPI hash, MPI *data, MPI *pkey,
- int (*cmp) (void *, MPI), void *opaque);
+static gpg_err_code_t pubkey_decrypt (int algo, MPI *result, MPI *data, MPI *skey, int flags);
+static gpg_err_code_t pubkey_sign (int algo, MPI *resarr, MPI hash, MPI *skey);
+static gpg_err_code_t pubkey_verify (int algo, MPI hash, MPI *data, MPI *pkey,
+ int (*cmp) (void *, MPI), void *opaque);
/* This is the list of the default public-key ciphers included in
libgcrypt. */
@@ -83,48 +81,48 @@ static int default_pubkeys_registered;
/* These dummy functions are used in case a cipher implementation
refuses to provide it's own functions. */
-static int
+static gpg_err_code_t
dummy_generate (int id, unsigned int nbits, unsigned long dummy,
MPI *skey, MPI **retfactors)
{
log_bug ("no generate() for %d\n", id);
- return GCRYERR_INV_PK_ALGO;
+ return GPG_ERR_PUBKEY_ALGO;
}
-static int
+static gpg_err_code_t
dummy_check_secret_key (int id, MPI *skey)
{
log_bug ("no check_secret_key() for %d\n", id);
- return GCRYERR_INV_PK_ALGO;
+ return GPG_ERR_PUBKEY_ALGO;
}
-static int
+static gpg_err_code_t
dummy_encrypt (int id, MPI *resarr, MPI data, MPI *pkey, int flags)
{
log_bug ("no encrypt() for %d\n", id);
- return GCRYERR_INV_PK_ALGO;
+ return GPG_ERR_PUBKEY_ALGO;
}
-static int
+static gpg_err_code_t
dummy_decrypt (int id, MPI *result, MPI *data, MPI *skey, int flags)
{
log_bug ("no decrypt() for %d\n", id);
- return GCRYERR_INV_PK_ALGO;
+ return GPG_ERR_PUBKEY_ALGO;
}
-static int
+static gpg_err_code_t
dummy_sign (int id, MPI *resarr, MPI data, MPI *skey)
{
log_bug ("no sign() for %d\n", id);
- return GCRYERR_INV_PK_ALGO;
+ return GPG_ERR_PUBKEY_ALGO;
}
-static int
+static gpg_err_code_t
dummy_verify (int id, MPI hash, MPI *data, MPI *pkey,
int (*cmp) (void *, MPI), void *opaquev)
{
log_bug ("no verify() for %d\n", id);
- return GCRYERR_INV_PK_ALGO;
+ return GPG_ERR_PUBKEY_ALGO;
}
static unsigned
@@ -139,7 +137,8 @@ dummy_get_nbits (int id, MPI *pkey)
static void
gcry_pubkey_register_default (void)
{
- int i, err = 0;
+ gpg_err_code_t err = 0;
+ int i;
for (i = 0; (! err) && pubkey_table[i].pubkey; i++)
{
@@ -229,16 +228,17 @@ gcry_pubkey_id_new (void)
/* Public function. Register a provided PUBKEY. Returns zero on
success, in which case the chosen pubkey ID has been stored in
PUBKEY, or an error code. */
-int
+gpg_error_t
gcry_pubkey_register (GcryPubkeySpec *pubkey, GcryModule **module)
{
- int id, err = 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ int id;
GcryModule *mod;
ath_mutex_lock (&pubkeys_registered_lock);
id = gcry_pubkey_id_new ();
if (! id)
- err = GCRYERR_INTERNAL; /* FIXME. */
+ err = GPG_ERR_INTERNAL; /* FIXME. */
else
{
pubkey->id = id;
@@ -341,12 +341,12 @@ disable_pubkey_algo (int id)
/****************
* a use of 0 means: don't care
*/
-static int
+static gpg_err_code_t
check_pubkey_algo (int id, unsigned use)
{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
GcryPubkeySpec *pubkey;
GcryModule *module;
- int err = 0;
REGISTER_DEFAULT_PUBKEYS;
@@ -360,13 +360,13 @@ check_pubkey_algo (int id, unsigned use)
&& (! (pubkey->use & GCRY_PK_USAGE_SIGN)))
|| ((use & GCRY_PK_USAGE_ENCR)
&& (! (pubkey->use & GCRY_PK_USAGE_ENCR))))
- err = GCRYERR_WRONG_PK_ALGO;
+ err = GPG_ERR_WRONG_PUBKEY_ALGO;
else if (module->flags & FLAG_MODULE_DISABLED)
- err = GCRYERR_INV_PK_ALGO;
+ err = GPG_ERR_PUBKEY_ALGO;
_gcry_module_release (module);
}
else
- err = GCRYERR_INV_PK_ALGO;
+ err = GPG_ERR_PUBKEY_ALGO;
ath_mutex_unlock (&pubkeys_registered_lock);
return err;
@@ -466,12 +466,12 @@ pubkey_get_nenc (int id)
}
-static int
+static gpg_err_code_t
pubkey_generate (int id, unsigned int nbits, unsigned long use_e,
MPI *skey, MPI **retfactors)
{
+ gpg_err_code_t err = GPG_ERR_PUBKEY_ALGO;
GcryModule *pubkey;
- int err = GCRYERR_INV_PK_ALGO;
REGISTER_DEFAULT_PUBKEYS;
@@ -488,11 +488,11 @@ pubkey_generate (int id, unsigned int nbits, unsigned long use_e,
return err;
}
-static int
+static gpg_err_code_t
pubkey_check_secret_key (int id, MPI *skey)
{
+ gpg_err_code_t err = GPG_ERR_PUBKEY_ALGO;
GcryModule *pubkey;
- int err = GCRYERR_INV_PK_ALGO;
REGISTER_DEFAULT_PUBKEYS;
@@ -515,13 +515,14 @@ pubkey_check_secret_key (int id, MPI *skey)
* should be an array of MPIs of size PUBKEY_MAX_NENC (or less if the
* algorithm allows this - check with pubkey_get_nenc() )
*/
-static int
+static gpg_err_code_t
pubkey_encrypt (int id, MPI *resarr, MPI data, MPI *pkey,
int flags)
{
GcryPubkeySpec *pubkey;
GcryModule *module;
- int i, rc;
+ gpg_err_code_t rc;
+ int i;
if (DBG_CIPHER)
{
@@ -540,7 +541,7 @@ pubkey_encrypt (int id, MPI *resarr, MPI data, MPI *pkey,
_gcry_module_release (module);
goto ready;
}
- rc = GCRYERR_INV_PK_ALGO;
+ rc = GPG_ERR_PUBKEY_ALGO;
ready:
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -561,13 +562,14 @@ pubkey_encrypt (int id, MPI *resarr, MPI data, MPI *pkey,
* result is a pointer to a mpi variable which will receive a
* newly allocated mpi or NULL in case of an error.
*/
-static int
+static gpg_err_code_t
pubkey_decrypt (int id, MPI *result, MPI *data, MPI *skey,
int flags)
{
GcryPubkeySpec *pubkey;
GcryModule *module;
- int i, rc;
+ gpg_err_code_t rc;
+ int i;
*result = NULL; /* so the caller can always do a mpi_free */
if (DBG_CIPHER)
@@ -589,7 +591,7 @@ pubkey_decrypt (int id, MPI *result, MPI *data, MPI *skey,
goto ready;
}
- rc = GCRYERR_INV_PK_ALGO;
+ rc = GPG_ERR_PUBKEY_ALGO;
ready:
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -607,12 +609,13 @@ pubkey_decrypt (int id, MPI *result, MPI *data, MPI *skey,
* should be an array of MPIs of size PUBKEY_MAX_NSIG (or less if the
* algorithm allows this - check with pubkey_get_nsig() )
*/
-static int
+static gpg_err_code_t
pubkey_sign (int id, MPI *resarr, MPI data, MPI *skey)
{
GcryPubkeySpec *pubkey;
GcryModule *module;
- int i, rc;
+ gpg_err_code_t rc;
+ int i;
if (DBG_CIPHER)
{
@@ -632,7 +635,7 @@ pubkey_sign (int id, MPI *resarr, MPI data, MPI *skey)
goto ready;
}
- rc = GCRYERR_INV_PK_ALGO;
+ rc = GPG_ERR_PUBKEY_ALGO;
ready:
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -648,13 +651,14 @@ pubkey_sign (int id, MPI *resarr, MPI data, MPI *skey)
* Verify a public key signature.
* Return 0 if the signature is good
*/
-static int
+static gpg_err_code_t
pubkey_verify (int id, MPI hash, MPI *data, MPI *pkey,
int (*cmp)(void *, MPI), void *opaquev)
{
GcryPubkeySpec *pubkey;
GcryModule *module;
- int i, rc;
+ gpg_err_code_t rc;
+ int i;
if (DBG_CIPHER)
{
@@ -676,7 +680,7 @@ pubkey_verify (int id, MPI hash, MPI *data, MPI *pkey,
goto ready;
}
- rc = GCRYERR_INV_PK_ALGO;
+ rc = GPG_ERR_PUBKEY_ALGO;
ready:
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -684,25 +688,26 @@ pubkey_verify (int id, MPI hash, MPI *data, MPI *pkey,
}
/* Internal function. */
-static int
-sexp_elements_extract (GCRY_SEXP key_sexp, const char *element_names,
- GCRY_MPI *elements)
+static gpg_err_code_t
+sexp_elements_extract (gcry_sexp_t key_sexp, const char *element_names,
+ gcry_mpi_t *elements)
{
- int i, index, err = 0;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ int i, index;
const char *name;
- GCRY_SEXP list;
+ gcry_sexp_t list;
for (name = element_names, index = 0; *name && (! err); name++, index++)
{
list = gcry_sexp_find_token (key_sexp, name, 1);
if (! list)
- err = GCRYERR_NO_OBJ;
+ err = GPG_ERR_NO_OBJ;
else
{
elements[index] = gcry_sexp_nth_mpi (list, 1, GCRYMPI_FMT_USG);
gcry_sexp_release (list);
if (! elements[index])
- err = GCRYERR_INV_OBJ;
+ err = GPG_ERR_INV_OBJ;
}
}
@@ -747,17 +752,17 @@ sexp_elements_extract (GCRY_SEXP key_sexp, const char *element_names,
* )
* The <mpi> are expected to be in GCRYMPI_FMT_USG
*/
-static int
-sexp_to_key (GCRY_SEXP sexp, int want_private, MPI **retarray,
+static gpg_err_code_t
+sexp_to_key (gcry_sexp_t sexp, int want_private, MPI **retarray,
GcryModule **retalgo)
{
- GCRY_SEXP list, l2;
+ gcry_sexp_t list, l2;
const char *name;
size_t n;
int algo;
const char *elems;
- GCRY_MPI *array;
- int err = 0;
+ gcry_mpi_t *array;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
GcryModule *module;
GcryPubkeySpec *pubkey;
@@ -765,14 +770,14 @@ sexp_to_key (GCRY_SEXP sexp, int want_private, MPI **retarray,
list = gcry_sexp_find_token( sexp, want_private? "private-key"
:"public-key", 0 );
if( !list )
- return GCRYERR_INV_OBJ; /* Does not contain a public- or private-key object */
+ return GPG_ERR_INV_OBJ; /* Does not contain a public- or private-key object */
l2 = gcry_sexp_cadr( list );
gcry_sexp_release ( list );
list = l2;
name = gcry_sexp_nth_data( list, 0, &n );
if( !name ) {
gcry_sexp_release ( list );
- return GCRYERR_INV_OBJ; /* invalid structure of object */
+ return GPG_ERR_INV_OBJ; /* invalid structure of object */
}
{
@@ -790,7 +795,7 @@ sexp_to_key (GCRY_SEXP sexp, int want_private, MPI **retarray,
if (! module)
{
gcry_sexp_release (list);
- return GCRYERR_INV_PK_ALGO; /* unknown algorithm */
+ return GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
}
else
pubkey = (GcryPubkeySpec *) module->spec;
@@ -799,8 +804,7 @@ sexp_to_key (GCRY_SEXP sexp, int want_private, MPI **retarray,
elems = want_private ? pubkey->elements_skey : pubkey->elements_pkey;
array = gcry_calloc (strlen (elems) + 1, sizeof (*array));
if (! array)
- err = GCRYERR_NO_MEM;
-
+ err = gpg_err_code_from_errno (errno);
if (! err)
err = sexp_elements_extract (list, elems, array);
@@ -825,33 +829,33 @@ sexp_to_key (GCRY_SEXP sexp, int want_private, MPI **retarray,
return err;
}
-static int
-sexp_to_sig (GCRY_SEXP sexp, MPI **retarray,
+static gpg_err_code_t
+sexp_to_sig (gcry_sexp_t sexp, MPI **retarray,
GcryModule **retalgo)
{
- GCRY_SEXP list, l2;
+ gcry_sexp_t list, l2;
const char *name;
size_t n;
int algo;
const char *elems;
- GCRY_MPI *array;
- int err = 0;
+ gcry_mpi_t *array;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
GcryModule *module;
GcryPubkeySpec *pubkey;
/* check that the first element is valid */
list = gcry_sexp_find_token( sexp, "sig-val" , 0 );
if( !list )
- return GCRYERR_INV_OBJ; /* Does not contain a signature value object */
+ return GPG_ERR_INV_OBJ; /* Does not contain a signature value object */
l2 = gcry_sexp_cadr( list );
gcry_sexp_release ( list );
list = l2;
if( !list )
- return GCRYERR_NO_OBJ; /* no cadr for the sig object */
+ return GPG_ERR_NO_OBJ; /* no cadr for the sig object */
name = gcry_sexp_nth_data( list, 0, &n );
if( !name ) {
gcry_sexp_release ( list );
- return GCRYERR_INV_OBJ; /* invalid structure of object */
+ return GPG_ERR_INV_OBJ; /* invalid structure of object */
}
{
@@ -869,7 +873,7 @@ sexp_to_sig (GCRY_SEXP sexp, MPI **retarray,
if (! module)
{
gcry_sexp_release (list);
- return GCRYERR_INV_PK_ALGO; /* unknown algorithm */
+ return GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
}
else
pubkey = (GcryPubkeySpec *) module->spec;
@@ -878,7 +882,7 @@ sexp_to_sig (GCRY_SEXP sexp, MPI **retarray,
elems = pubkey->elements_sig;
array = gcry_calloc (strlen (elems) + 1 , sizeof (*array));
if (! array)
- err = GCRYERR_NO_MEM;
+ err = gpg_err_code_from_errno (errno);
if (! err)
err = sexp_elements_extract (list, elems, array);
@@ -917,19 +921,19 @@ sexp_to_sig (GCRY_SEXP sexp, MPI **retarray,
* ))
* RET_MODERN is set to true when at least an empty flags list has been found.
*/
-static int
-sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
+static gpg_err_code_t
+sexp_to_enc (gcry_sexp_t sexp, MPI **retarray, GcryModule **retalgo,
int *ret_modern, int *ret_want_pkcs1, int *flags)
{
- GCRY_SEXP list = NULL, l2 = NULL;
+ gcry_sexp_t list = NULL, l2 = NULL;
GcryPubkeySpec *pubkey = NULL;
GcryModule *module = NULL;
const char *name;
size_t n;
int parsed_flags = 0;
const char *elems;
- GCRY_MPI *array = NULL;
- int err = 0;
+ gcry_mpi_t *array = NULL;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
*ret_want_pkcs1 = 0;
*ret_modern = 0;
@@ -937,13 +941,13 @@ sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
/* check that the first element is valid */
list = gcry_sexp_find_token (sexp, "enc-val" , 0);
if (! list)
- err = GCRYERR_INV_OBJ; /* Does not contain an encrypted value object */
+ err = GPG_ERR_INV_OBJ; /* Does not contain an encrypted value object */
if (! err)
{
l2 = gcry_sexp_nth (list, 1);
if (! l2)
- err = GCRYERR_NO_OBJ; /* no cdr for the data object */
+ err = GPG_ERR_NO_OBJ; /* no cdr for the data object */
}
if (! err)
@@ -951,7 +955,7 @@ sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
/* Extract the name of the algorithm. */
name = gcry_sexp_nth_data (l2, 0, &n);
if (! name)
- err = GCRYERR_INV_OBJ; /* invalid structure of object */
+ err = GPG_ERR_INV_OBJ; /* invalid structure of object */
}
if ((! err) && (n == 5) && (! memcmp (name, "flags", 5)))
@@ -973,7 +977,7 @@ sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
else if (n == 11 && ! memcmp (s, "no-blinding", 11))
parsed_flags |= PUBKEY_FLAG_NO_BLINDING;
else
- err = GCRYERR_INV_FLAG;
+ err = GPG_ERR_INV_FLAG;
}
}
@@ -983,14 +987,14 @@ sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
gcry_sexp_release (l2);
l2 = gcry_sexp_nth (list, 2);
if (! l2)
- err = GCRYERR_NO_OBJ; /* no cdr for the data object */
+ err = GPG_ERR_NO_OBJ; /* no cdr for the data object */
}
if (! err)
{
name = gcry_sexp_nth_data (l2, 0, &n);
if (! name)
- err = GCRYERR_INV_OBJ; /* invalid structure of object */
+ err = GPG_ERR_INV_OBJ; /* invalid structure of object */
else
{
gcry_sexp_release (list);
@@ -1012,7 +1016,7 @@ sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
free (name_terminated);
if (! module)
- err = GCRYERR_INV_PK_ALGO; /* unknown algorithm */
+ err = GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
else
pubkey = (GcryPubkeySpec *) module->spec;
}
@@ -1022,7 +1026,7 @@ sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
elems = pubkey->elements_enc;
array = gcry_calloc (strlen (elems) + 1, sizeof (*array));
if (! array)
- err = GCRYERR_NO_MEM;
+ err = gpg_err_code_from_errno (errno);
}
if (! err)
@@ -1071,12 +1075,12 @@ sexp_to_enc (GCRY_SEXP sexp, MPI **retarray, GcryModule **retalgo,
NBITS is the length of the key in bits.
*/
-static int
-sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
+static gpg_err_code_t
+sexp_data_to_mpi (gcry_sexp_t input, unsigned int nbits, gcry_mpi_t *ret_mpi,
int for_encryption, int *flags)
{
- int rc = 0;
- GcrySexp ldata, lhash, lvalue;
+ gpg_err_code_t rc = 0;
+ gcry_sexp_t ldata, lhash, lvalue;
int i;
size_t n;
const char *s;
@@ -1091,12 +1095,12 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
if (!ldata)
{ /* assume old style */
*ret_mpi = gcry_sexp_nth_mpi (input, 0, 0);
- return *ret_mpi? 0 : GCRYERR_INV_OBJ;
+ return *ret_mpi ? GPG_ERR_NO_ERROR : GPG_ERR_INV_OBJ;
}
/* see whether there is a flags object */
{
- GcrySexp lflags = gcry_sexp_find_token (ldata, "flags", 0);
+ gcry_sexp_t lflags = gcry_sexp_find_token (ldata, "flags", 0);
if (lflags)
{ /* parse the flags list. */
for (i=gcry_sexp_length (lflags)-1; i > 0; i--)
@@ -1125,16 +1129,16 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
lvalue = lhash? NULL : gcry_sexp_find_token (ldata, "value", 0);
if (!(!lhash ^ !lvalue))
- rc = GCRYERR_INV_OBJ; /* none or both given */
+ rc = GPG_ERR_INV_OBJ; /* none or both given */
else if (unknown_flag)
- rc = GCRYERR_INV_FLAG;
+ rc = GPG_ERR_INV_FLAG;
else if (is_raw && is_pkcs1 && !for_encryption)
- rc = GCRYERR_CONFLICT;
+ rc = GPG_ERR_CONFLICT;
else if (is_raw && lvalue)
{
*ret_mpi = gcry_sexp_nth_mpi (lvalue, 1, 0);
if (!*ret_mpi)
- rc = GCRYERR_INV_OBJ;
+ rc = GPG_ERR_INV_OBJ;
}
else if (is_pkcs1 && lvalue && for_encryption)
{ /* create pkcs#1 block type 2 padding */
@@ -1145,14 +1149,14 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
unsigned char *p;
if ( !(value=gcry_sexp_nth_data (lvalue, 1, &valuelen)) || !valuelen )
- rc = GCRYERR_INV_OBJ;
+ rc = GPG_ERR_INV_OBJ;
else if (valuelen + 7 > nframe || !nframe)
{
/* Can't encode a VALUELEN value in a NFRAME bytes frame. */
- rc = GCRYERR_TOO_SHORT; /* the key is too short */
+ rc = GPG_ERR_TOO_SHORT; /* the key is too short */
}
else if ( !(frame = gcry_malloc_secure (nframe)))
- rc = GCRYERR_NO_MEM;
+ rc = gpg_err_code_from_errno (errno);
else
{
n = 0;
@@ -1194,6 +1198,7 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
n += valuelen;
assert (n == nframe);
+ /* FIXME, error checking? */
gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, &nframe);
}
@@ -1202,9 +1207,9 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
else if (is_pkcs1 && lhash && !for_encryption)
{ /* create pkcs#1 block type 1 padding */
if (gcry_sexp_length (lhash) != 3)
- rc = GCRYERR_INV_OBJ;
+ rc = GPG_ERR_INV_OBJ;
else if ( !(s=gcry_sexp_nth_data (lhash, 1, &n)) || !n )
- rc = GCRYERR_INV_OBJ;
+ rc = GPG_ERR_INV_OBJ;
else
{
static struct { const char *name; int algo; } hashnames[] =
@@ -1240,25 +1245,25 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
dlen = gcry_md_get_algo_dlen (algo);
if (!hashnames[i].name)
- rc = GCRYERR_INV_MD_ALGO;
+ rc = GPG_ERR_DIGEST_ALGO;
else if ( !(value=gcry_sexp_nth_data (lhash, 2, &valuelen))
|| !valuelen )
- rc = GCRYERR_INV_OBJ;
+ rc = GPG_ERR_INV_OBJ;
else if (gcry_md_algo_info (algo, GCRYCTL_GET_ASNOID, asn, &asnlen))
- rc = GCRYERR_NOT_IMPL; /* we don't have all of the above algos */
+ rc = GPG_ERR_NOT_IMPLEMENTED; /* we don't have all of the above algos */
else if ( valuelen != dlen )
{
/* hash value does not match the length of digest for
the given algo */
- rc = GCRYERR_CONFLICT;
+ rc = GPG_ERR_CONFLICT;
}
else if( !dlen || dlen + asnlen + 4 > nframe)
{
/* can't encode an DLEN byte digest MD into a NFRAME byte frame */
- rc = GCRYERR_TOO_SHORT;
+ rc = GPG_ERR_TOO_SHORT;
}
else if ( !(frame = gcry_malloc (nframe)) )
- rc = GCRYERR_NO_MEM;
+ rc = gpg_err_code_from_errno (errno);
else
{ /* assemble the pkcs#1 block type 1 */
n = 0;
@@ -1275,7 +1280,7 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
n += valuelen;
assert (n == nframe);
- /* convert it into an MPI */
+ /* convert it into an MPI, FIXME: error checking? */
gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, &nframe);
}
@@ -1283,7 +1288,7 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
}
}
else
- rc = GCRYERR_CONFLICT;
+ rc = GPG_ERR_CONFLICT;
gcry_sexp_release (ldata);
gcry_sexp_release (lhash);
@@ -1318,12 +1323,13 @@ sexp_data_to_mpi (GcrySexp input, unsigned int nbits, GcryMPI *ret_mpi,
))
*/
-int
-gcry_pk_encrypt (GCRY_SEXP *r_ciph, GCRY_SEXP s_data, GCRY_SEXP s_pkey)
+gpg_error_t
+gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey)
{
MPI *pkey = NULL, data = NULL, *ciph = NULL;
const char *algo_name, *algo_elems;
- int rc, flags;
+ int flags;
+ gpg_err_code_t rc;
GcryPubkeySpec *pubkey = NULL;
GcryModule *module = NULL;
@@ -1358,9 +1364,10 @@ gcry_pk_encrypt (GCRY_SEXP *r_ciph, GCRY_SEXP s_data, GCRY_SEXP s_pkey)
char *string, *p;
int i;
size_t nelem = strlen (algo_elems);
- size_t needed = 18 + (nelem * 5);
+ size_t needed = 19 + strlen (algo_name) + (nelem * 5);
+
if (flags & PUBKEY_FLAG_NO_BLINDING)
- needed += 12; /* FIXME, verify calculation? */
+ needed += 12;
/* Build the string. */
string = p = gcry_xmalloc (needed);
@@ -1379,27 +1386,23 @@ gcry_pk_encrypt (GCRY_SEXP *r_ciph, GCRY_SEXP s_data, GCRY_SEXP s_pkey)
/* and now the ugly part: we don't have a function to
* pass an array to a format string, so we have to do it this way :-(
*/
- switch ( nelem ) {
- case 1: rc = gcry_sexp_build ( r_ciph, NULL, string,
- ciph[0]
- ); break;
- case 2: rc = gcry_sexp_build ( r_ciph, NULL, string,
- ciph[0], ciph[1]
- ); break;
- case 3: rc = gcry_sexp_build ( r_ciph, NULL, string,
- ciph[0], ciph[1], ciph[2]
- ); break;
- case 4: rc = gcry_sexp_build ( r_ciph, NULL, string,
- ciph[0], ciph[1], ciph[2], ciph[3]
- ); break;
- case 5: rc = gcry_sexp_build ( r_ciph, NULL, string,
- ciph[0], ciph[1], ciph[2], ciph[3], ciph[4]
- ); break;
- case 6: rc = gcry_sexp_build ( r_ciph, NULL, string,
- ciph[0], ciph[1], ciph[2], ciph[3], ciph[4], ciph[5]
- ); break;
- default: BUG ();
+
+ {
+ int i;
+ void **arg_list = malloc (sizeof (void *) * nelem);
+ if (arg_list)
+ {
+ for (i = 0; i < nelem; i++)
+ arg_list[i] = &ciph[i];
+
+ rc = gcry_sexp_build_array (r_ciph, NULL, string, arg_list);
+
+ free (arg_list);
+ }
+ else
+ rc = gpg_err_code_from_errno (errno);
}
+
if (rc)
BUG ();
gcry_free (string);
@@ -1418,7 +1421,7 @@ gcry_pk_encrypt (GCRY_SEXP *r_ciph, GCRY_SEXP s_data, GCRY_SEXP s_pkey)
ath_mutex_unlock (&pubkeys_registered_lock);
}
- return rc;
+ return gpg_error (rc);
}
/****************
@@ -1428,7 +1431,7 @@ gcry_pk_encrypt (GCRY_SEXP *r_ciph, GCRY_SEXP s_data, GCRY_SEXP s_pkey)
* format as created by gcry_pk_encrypt. For historic reasons the
* function returns simply an MPI as an S-expression part; this is
* deprecated and the new method should be used which returns a real
- * S-expressionl this is selected by adding at least an empt flags
+ * S-expressionl this is selected by adding at least an empty flags
* list to S_DATA.
*
* Returns: 0 or an errorcode.
@@ -1444,11 +1447,12 @@ gcry_pk_encrypt (GCRY_SEXP *r_ciph, GCRY_SEXP s_data, GCRY_SEXP s_pkey)
* r_plain= Either an incomplete S-expression without the parentheses
* or if the flags list is used (even if empty) a real S-expression:
* (value PLAIN). */
-int
-gcry_pk_decrypt (GCRY_SEXP *r_plain, GCRY_SEXP s_data, GCRY_SEXP s_skey)
+gpg_error_t
+gcry_pk_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t s_skey)
{
MPI *skey = NULL, *data = NULL, plain = NULL;
- int rc, modern, want_pkcs1, flags;
+ int modern, want_pkcs1, flags;
+ gpg_err_code_t rc;
GcryModule *module_enc = NULL, *module_key = NULL;
GcryPubkeySpec *pubkey = NULL;
@@ -1464,7 +1468,7 @@ gcry_pk_decrypt (GCRY_SEXP *r_plain, GCRY_SEXP s_data, GCRY_SEXP s_skey)
{
if (((GcryPubkeySpec *) module_key->spec)->id
!= ((GcryPubkeySpec *) module_enc->spec)->id)
- rc = GCRYERR_CONFLICT; /* key algo does not match data algo */
+ rc = GPG_ERR_CONFLICT; /* key algo does not match data algo */
else
pubkey = (GcryPubkeySpec *) module_key->spec;
}
@@ -1511,7 +1515,7 @@ gcry_pk_decrypt (GCRY_SEXP *r_plain, GCRY_SEXP s_data, GCRY_SEXP s_skey)
ath_mutex_unlock (&pubkeys_registered_lock);
}
- return rc;
+ return gpg_error (rc);
}
@@ -1541,14 +1545,15 @@ gcry_pk_decrypt (GCRY_SEXP *r_plain, GCRY_SEXP s_data, GCRY_SEXP s_skey)
* ...
* (<param_namen> <mpi>)
* )) */
-int
-gcry_pk_sign (GCRY_SEXP *r_sig, GCRY_SEXP s_hash, GCRY_SEXP s_skey)
+gpg_error_t
+gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey)
{
MPI *skey = NULL, hash = NULL, *result = NULL;
GcryPubkeySpec *pubkey = NULL;
GcryModule *module = NULL;
const char *key_algo_name, *algo_name, *algo_elems;
- int i, rc;
+ int i;
+ gpg_err_code_t rc;
REGISTER_DEFAULT_PUBKEYS;
@@ -1597,31 +1602,22 @@ gcry_pk_sign (GCRY_SEXP *r_sig, GCRY_SEXP s_hash, GCRY_SEXP s_skey)
}
strcpy (p, "))");
- /* and now the ugly part: we don't have a function to
- * pass an array to a format string, so we have to do it this way :-(
- */
- switch (nelem)
- {
- case 1: rc = gcry_sexp_build ( r_sig, NULL, string,
- result[0]
- ); break;
- case 2: rc = gcry_sexp_build ( r_sig, NULL, string,
- result[0], result[1]
- ); break;
- case 3: rc = gcry_sexp_build ( r_sig, NULL, string,
- result[0], result[1], result[2]
- ); break;
- case 4: rc = gcry_sexp_build ( r_sig, NULL, string,
- result[0], result[1], result[2], result[3]
- ); break;
- case 5: rc = gcry_sexp_build ( r_sig, NULL, string,
- result[0], result[1], result[2], result[3], result[4]
- ); break;
- case 6: rc = gcry_sexp_build ( r_sig, NULL, string,
- result[0], result[1], result[2], result[3], result[4], result[5]
- ); break;
- default: BUG ();
- }
+ {
+ int i;
+ void **arg_list = malloc (sizeof (void *) * nelem);
+ if (arg_list)
+ {
+ for (i = 0; i < nelem; i++)
+ arg_list[i] = &result[i];
+
+ rc = gcry_sexp_build_array (r_sig, NULL, string, arg_list);
+
+ free (arg_list);
+ }
+ else
+ rc = gpg_err_code_from_errno (errno);
+ }
+
if (rc)
BUG ();
gcry_free (string);
@@ -1639,7 +1635,7 @@ gcry_pk_sign (GCRY_SEXP *r_sig, GCRY_SEXP s_hash, GCRY_SEXP s_skey)
if (result)
gcry_free (result);
- return rc;
+ return gpg_error (rc);
}
@@ -1650,12 +1646,12 @@ gcry_pk_sign (GCRY_SEXP *r_sig, GCRY_SEXP s_hash, GCRY_SEXP s_skey)
* from gcry_pk_sign and data must be an S-Exp like the one in sign
* too.
*/
-int
-gcry_pk_verify (GCRY_SEXP s_sig, GCRY_SEXP s_hash, GCRY_SEXP s_pkey)
+gpg_error_t
+gcry_pk_verify (gcry_sexp_t s_sig, gcry_sexp_t s_hash, gcry_sexp_t s_pkey)
{
GcryModule *module_key = NULL, *module_sig = NULL;
MPI *pkey = NULL, hash = NULL, *sig = NULL;
- int rc;
+ gpg_err_code_t rc;
REGISTER_DEFAULT_PUBKEYS;
@@ -1666,7 +1662,7 @@ gcry_pk_verify (GCRY_SEXP s_sig, GCRY_SEXP s_hash, GCRY_SEXP s_pkey)
if ((! rc)
&& (((GcryPubkeySpec *) module_key->spec)->id
!= ((GcryPubkeySpec *) module_sig->spec)->id))
- rc = GCRYERR_CONFLICT;
+ rc = GPG_ERR_CONFLICT;
if (! rc)
rc = sexp_data_to_mpi (s_hash, gcry_pk_get_nbits (s_pkey), &hash, 0, 0);
@@ -1698,7 +1694,7 @@ gcry_pk_verify (GCRY_SEXP s_sig, GCRY_SEXP s_hash, GCRY_SEXP s_pkey)
ath_mutex_unlock (&pubkeys_registered_lock);
}
- return rc;
+ return gpg_error (rc);
}
@@ -1710,13 +1706,15 @@ gcry_pk_verify (GCRY_SEXP s_sig, GCRY_SEXP s_hash, GCRY_SEXP s_pkey)
*
* s_key = <key-as-defined-in-sexp_to_key>
*/
-int
-gcry_pk_testkey (GCRY_SEXP s_key)
+gpg_error_t
+gcry_pk_testkey (gcry_sexp_t s_key)
{
GcryModule *module = NULL;
MPI *key = NULL;
- int rc;
+ gpg_err_code_t rc;
+ REGISTER_DEFAULT_PUBKEYS;
+
/* Note we currently support only secret key checking */
rc = sexp_to_key (s_key, 1, &key, &module);
if (! rc)
@@ -1725,7 +1723,7 @@ gcry_pk_testkey (GCRY_SEXP s_key)
release_mpi_array (key);
gcry_free (key);
}
- return rc;
+ return gpg_error (rc);
}
@@ -1763,19 +1761,20 @@ gcry_pk_testkey (GCRY_SEXP s_key)
* )
* )
*/
-int
-gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
+gpg_error_t
+gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
{
GcryPubkeySpec *pubkey = NULL;
GcryModule *module = NULL;
- GCRY_SEXP list = NULL, l2 = NULL;
+ gcry_sexp_t list = NULL, l2 = NULL;
const char *name;
size_t n;
- int rc = 0, i;
+ gpg_err_code_t rc = GPG_ERR_NO_ERROR;
+ int i;
const char *algo_name = NULL;
int algo;
const char *sec_elems = NULL, *pub_elems = NULL;
- GCRY_MPI skey[10] = { NULL }, *factors = NULL;
+ gcry_mpi_t skey[10] = { NULL }, *factors = NULL;
unsigned int nbits = 0;
unsigned long use_e = 0;
@@ -1784,7 +1783,7 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
*r_key = NULL;
list = gcry_sexp_find_token (s_parms, "genkey", 0);
if (! list)
- rc = GCRYERR_INV_OBJ; /* Does not contain genkey data */
+ rc = GPG_ERR_INV_OBJ; /* Does not contain genkey data */
if (! rc)
{
@@ -1793,14 +1792,14 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
list = l2;
l2 = NULL;
if (! list)
- rc = GCRYERR_NO_OBJ; /* no cdr for the genkey */
+ rc = GPG_ERR_NO_OBJ; /* no cdr for the genkey */
}
if (! rc)
{
name = gcry_sexp_nth_data (list, 0, &n);
if (! name)
- rc = GCRYERR_INV_OBJ; /* algo string missing */
+ rc = GPG_ERR_INV_OBJ; /* algo string missing */
}
if (! rc)
@@ -1809,14 +1808,14 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
strncpy (name_terminated, name, n);
name_terminated[n] = 0;
- ath_mutex_unlock (&pubkeys_registered_lock);
+ ath_mutex_lock (&pubkeys_registered_lock);
module = gcry_pubkey_lookup_name (name_terminated);
ath_mutex_unlock (&pubkeys_registered_lock);
free (name_terminated);
if (! module)
- rc = GCRYERR_INV_PK_ALGO; /* unknown algorithm */
+ rc = GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
else
{
pubkey = (GcryPubkeySpec *) module->spec;
@@ -1836,7 +1835,7 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
name = gcry_sexp_nth_data (l2, 1, &n);
if ((! name) || (n >= DIM (buf) - 1))
- rc = GCRYERR_INV_OBJ; /* no value or value too large */
+ rc = GPG_ERR_INV_OBJ; /* no value or value too large */
else
{
memcpy (buf, name, n);
@@ -1857,12 +1856,12 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
list = l2;
l2 = NULL;
if (! list)
- rc = GCRYERR_NO_OBJ; /* no nbits parameter */
+ rc = GPG_ERR_NO_OBJ; /* no nbits parameter */
else
{
name = gcry_sexp_nth_data (list, 1, &n);
if (! name)
- rc = GCRYERR_INV_OBJ; /* nbits without a cdr */
+ rc = GPG_ERR_INV_OBJ; /* nbits without a cdr */
else
{
char *p = gcry_xmalloc (n + 1);
@@ -1880,12 +1879,14 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
if (! rc)
{
char *string, *p;
- size_t nelem=0, needed=0;
- GCRY_MPI mpis[30];
+ size_t nelem=0, nelem_cp = 0, needed=0;
+ gcry_mpi_t mpis[30];
nelem = strlen (pub_elems) + strlen (sec_elems);
for (i = 0; factors[i]; i++)
nelem++;
+ nelem_cp = nelem;
+
needed += nelem * 10;
needed += 2 * strlen (algo_name) + 300;
if (nelem > DIM (mpis))
@@ -1930,17 +1931,25 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
while (nelem < DIM (mpis))
mpis[nelem++] = NULL;
- /* and now the ugly part: we don't have a function to pass an
- * array to a format string, so we have just pass everything we
- * have. which normally should be no problem as only those with
- * a corresponding %m are used
- */
- if (gcry_sexp_build (r_key, NULL, string,
- mpis[0], mpis[1], mpis[2], mpis[3], mpis[4], mpis[5],
- mpis[6], mpis[7], mpis[8], mpis[9], mpis[10], mpis[11],
- mpis[12], mpis[13], mpis[14], mpis[15], mpis[16], mpis[17],
- mpis[18], mpis[19], mpis[20], mpis[21], mpis[22], mpis[23],
- mpis[24], mpis[25], mpis[26], mpis[27], mpis[28], mpis[29]))
+ {
+ int elem_n = strlen (pub_elems) + strlen (sec_elems), i;
+ void **arg_list = malloc (sizeof (void *) * nelem_cp);
+ if (arg_list)
+ {
+ for (i = 0; i < elem_n; i++)
+ arg_list[i] = &mpis[i];
+ for (; i < nelem_cp; i++)
+ arg_list[i] = &factors[i - elem_n];
+
+ rc = gcry_sexp_build_array (r_key, NULL, string, arg_list);
+
+ free (arg_list);
+ }
+ else
+ rc = gpg_err_code_from_errno (errno);
+ }
+
+ if (rc)
BUG ();
assert (DIM (mpis) == 30); /* ? */
gcry_free (string);
@@ -1967,7 +1976,7 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
ath_mutex_unlock (&pubkeys_registered_lock);
}
- return rc;
+ return gpg_error (rc);
}
/****************
@@ -1977,18 +1986,18 @@ gcry_pk_genkey (GCRY_SEXP *r_key, GCRY_SEXP s_parms)
* different propoerties of the key?
*/
unsigned int
-gcry_pk_get_nbits (GCRY_SEXP key)
+gcry_pk_get_nbits (gcry_sexp_t key)
{
GcryModule *module = NULL;
GcryPubkeySpec *pubkey;
MPI *keyarr = NULL;
unsigned int nbits = 0;
- int rc;
+ gpg_err_code_t rc;
REGISTER_DEFAULT_PUBKEYS;
rc = sexp_to_key (key, 0, &keyarr, &module);
- if (rc == GCRYERR_INV_OBJ)
+ if (rc == GPG_ERR_INV_OBJ)
rc = sexp_to_key (key, 1, &keyarr, &module);
if (rc)
return 0;
@@ -2017,9 +2026,9 @@ gcry_pk_get_nbits (GCRY_SEXP key)
NULL is returned to indicate an error which is most likely an
unknown algorithm. The function accepts public or secret keys. */
unsigned char *
-gcry_pk_get_keygrip (GCRY_SEXP key, unsigned char *array)
+gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array)
{
- GCRY_SEXP list = NULL, l2 = NULL;
+ gcry_sexp_t list = NULL, l2 = NULL;
GcryPubkeySpec *pubkey = NULL;
GcryModule *module = NULL;
const char *s, *name;
@@ -2027,7 +2036,7 @@ gcry_pk_get_keygrip (GCRY_SEXP key, unsigned char *array)
int idx;
int is_rsa;
const char *elems;
- GCRY_MD_HD md = NULL;
+ gcry_md_hd_t md = NULL;
REGISTER_DEFAULT_PUBKEYS;
@@ -2074,8 +2083,7 @@ gcry_pk_get_keygrip (GCRY_SEXP key, unsigned char *array)
if (! elems)
goto fail; /* no grip parameter */
- md = gcry_md_open (GCRY_MD_SHA1, 0);
- if (! md)
+ if (gcry_md_open (&md, GCRY_MD_SHA1, 0))
goto fail;
for (idx = 0, s = elems; *s; s++, idx++)
@@ -2128,24 +2136,30 @@ gcry_pk_get_keygrip (GCRY_SEXP key, unsigned char *array)
}
-
-int
-gcry_pk_ctl( int cmd, void *buffer, size_t buflen)
+gpg_error_t
+gcry_pk_ctl (int cmd, void *buffer, size_t buflen)
{
- switch( cmd ) {
- case GCRYCTL_DISABLE_ALGO:
- /* this one expects a buffer pointing to an
- * integer with the algo number.
- */
- if( !buffer || buflen != sizeof(int) )
- return set_lasterr( GCRYERR_INV_CIPHER_ALGO );
- disable_pubkey_algo( *(int*)buffer );
- break;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
+ REGISTER_DEFAULT_PUBKEYS;
+
+ switch (cmd)
+ {
+ case GCRYCTL_DISABLE_ALGO:
+ /* this one expects a buffer pointing to an integer with the
+ * algo number.
+ */
+ if ((! buffer) || (buflen != sizeof (int)))
+ err = GPG_ERR_CIPHER_ALGO; /* FIXME? */
+ else
+ disable_pubkey_algo (*((int *) buffer));
+ break;
- default:
- return set_lasterr( GCRYERR_INV_OP );
+ default:
+ err = GPG_ERR_INV_OP;
}
- return 0;
+
+ return gpg_error (err);
}
@@ -2163,34 +2177,28 @@ gcry_pk_ctl( int cmd, void *buffer, size_t buflen)
* only want to know whether the algo is at all capable of
* the usage.
*
- * On error the value -1 is returned and the error reason may be
- * retrieved by gcry_errno().
* Note: Because this function is in most cases used to return an
* integer value, we can make it easier for the caller to just look at
* the return value. The caller will in all cases consult the value
* and thereby detecting whether a error occured or not (i.e. while checking
* the block size)
*/
-int
+gpg_error_t
gcry_pk_algo_info (int id, int what, void *buffer, size_t *nbytes)
{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
switch (what)
{
case GCRYCTL_TEST_ALGO:
{
- int use = nbytes ? *nbytes: 0;
+ int use = nbytes ? *nbytes : 0;
if (buffer)
- {
- set_lasterr( GCRYERR_INV_ARG );
- return -1;
- }
- if (check_pubkey_algo (id, use))
- {
- set_lasterr( GCRYERR_INV_PK_ALGO );
- return -1;
- }
+ err = GPG_ERR_INV_ARG;
+ else if (check_pubkey_algo (id, use))
+ err = GPG_ERR_PUBKEY_ALGO;
+ break;
}
- break;
case GCRYCTL_GET_ALGO_USAGE:
{
@@ -2207,22 +2215,43 @@ gcry_pk_algo_info (int id, int what, void *buffer, size_t *nbytes)
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
- return use;
+
+ /* FIXME? */
+ *nbytes = use;
}
case GCRYCTL_GET_ALGO_NPKEY:
- return pubkey_get_npkey (id);
+ {
+ /* FIXME? */
+ int npkey = pubkey_get_npkey (id);
+ *nbytes = npkey;
+ break;
+ }
case GCRYCTL_GET_ALGO_NSKEY:
- return pubkey_get_nskey (id);
+ {
+ /* FIXME? */
+ int nskey = pubkey_get_nskey (id);
+ *nbytes = nskey;
+ break;
+ }
case GCRYCTL_GET_ALGO_NSIGN:
- return pubkey_get_nsig (id);
+ {
+ /* FIXME? */
+ int nsign = pubkey_get_nsig (id);
+ *nbytes = nsign;
+ break;
+ }
case GCRYCTL_GET_ALGO_NENCR:
- return pubkey_get_nenc (id);
+ {
+ /* FIXME? */
+ int nencr = pubkey_get_nenc (id);
+ *nbytes = nencr;
+ break;
+ }
default:
- set_lasterr (GCRYERR_INV_OP);
- return -1;
+ err = GPG_ERR_INV_OP;
}
- return 0;
+ return gpg_error (err);
}
diff --git a/cipher/random.c b/cipher/random.c
index 8df2c56b..f1be289b 100644
--- a/cipher/random.c
+++ b/cipher/random.c
@@ -38,16 +38,16 @@
#include <fcntl.h>
#include <time.h>
#ifdef HAVE_GETHRTIME
- #include <sys/times.h>
+#include <sys/times.h>
#endif
#ifdef HAVE_GETTIMEOFDAY
- #include <sys/times.h>
+#include <sys/times.h>
#endif
#ifdef HAVE_GETRUSAGE
- #include <sys/resource.h>
+#include <sys/resource.h>
#endif
#ifdef __MINGW32__
- #include <process.h>
+#include <process.h>
#endif
#include "g10lib.h"
#include "rmd.h"
@@ -58,16 +58,16 @@
#include "ath.h"
#ifndef RAND_MAX /* for SunOS */
- #define RAND_MAX 32767
+#define RAND_MAX 32767
#endif
#if SIZEOF_UNSIGNED_LONG == 8
- #define ADD_VALUE 0xa5a5a5a5a5a5a5a5
+#define ADD_VALUE 0xa5a5a5a5a5a5a5a5
#elif SIZEOF_UNSIGNED_LONG == 4
- #define ADD_VALUE 0xa5a5a5a5
+#define ADD_VALUE 0xa5a5a5a5
#else
- #error weird size for an unsigned long
+#error weird size for an unsigned long
#endif
#define BLOCKLEN 64 /* hash this amount of bytes */
@@ -80,7 +80,7 @@
#define POOLBLOCKS 30
#define POOLSIZE (POOLBLOCKS*DIGESTLEN)
#if (POOLSIZE % SIZEOF_UNSIGNED_LONG)
- #error Please make sure that poolsize is a multiple of ulong
+#error Please make sure that poolsize is a multiple of ulong
#endif
#define POOLWORDS (POOLSIZE / SIZEOF_UNSIGNED_LONG)
@@ -281,18 +281,23 @@ get_random_bytes( size_t nbytes, int level, int secure )
Note, that this fucntion currently does nothing.
*/
-int
+gpg_error_t
gcry_random_add_bytes (const void * buf, size_t buflen, int quality)
{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
if (!buf || quality < -1 || quality > 100)
- return GCRYERR_INV_ARG;
+ err = GPG_ERR_INV_ARG;
+ /* FIXME */
+#if 0
if (!buflen)
return 0; /* Shortcut this dummy case. */
/* Before we actuall enbale this code, we need to lock the pool,
have a look at the quality and find a way to add them without
disturbing the real entropy (we have estimated). */
/*add_randomness( buf, buflen, 1 );*/
- return 0;
+#endif
+ return err;
}
@@ -406,7 +411,7 @@ mix_pool(byte *pool)
assert (pool_is_locked);
_gcry_rmd160_init( &md );
#if DIGESTLEN != 20
-# error must have a digest length of 20 for ripe-md-160
+#error must have a digest length of 20 for ripe-md-160
#endif
/* loop over the pool */
pend = pool + POOLSIZE;
@@ -475,11 +480,11 @@ read_seed_file()
if( !seed_file_name )
return 0;
- #ifdef HAVE_DOSISH_SYSTEM
+#ifdef HAVE_DOSISH_SYSTEM
fd = open( seed_file_name, O_RDONLY | O_BINARY );
- #else
+#else
fd = open( seed_file_name, O_RDONLY );
- #endif
+#endif
if( fd == -1 && errno == ENOENT) {
allow_seed_file_update = 1;
return 0;
@@ -759,44 +764,44 @@ getfnc_gather_random (void))(void (*)(const void*, size_t, int), int,
if (fnc)
return fnc;
-# if USE_RNDLINUX
+#if USE_RNDLINUX
if ( !access (NAME_OF_DEV_RANDOM, R_OK)
&& !access (NAME_OF_DEV_RANDOM, R_OK))
{
fnc = rndlinux_gather_random;
return fnc;
}
-# endif
-# if USE_RNDEGD
+#endif
+#if USE_RNDEGD
if ( rndegd_connect_socket (1) != -1 )
{
fnc = rndegd_gather_random;
return fnc;
}
-# endif
-# if USE_RNDUNIX
+#endif
+#if USE_RNDUNIX
fnc = rndunix_gather_random;
return fnc;
-# endif
+#endif
log_fatal (_("no entropy gathering module detected\n"));
#else
-# if USE_RNDLINUX
+#if USE_RNDLINUX
return rndlinux_gather_random;
-# endif
-# if USE_RNDUNIX
+#endif
+#if USE_RNDUNIX
return rndunix_gather_random;
-# endif
-# if USE_RNDEGD
+#endif
+#if USE_RNDEGD
return rndegd_gather_random;
-# endif
-# if USE_RNDW32
+#endif
+#if USE_RNDW32
return rndw32_gather_random;
-# endif
-# if USE_RNDRISCOS
+#endif
+#if USE_RNDRISCOS
return rndriscos_gather_random;
-# endif
+#endif
#endif
return NULL;
}
@@ -833,39 +838,39 @@ do_fast_random_poll ()
}
/* fall back to the generic function */
- #if HAVE_GETHRTIME
+#if HAVE_GETHRTIME
{ hrtime_t tv;
tv = gethrtime();
add_randomness( &tv, sizeof(tv), 1 );
}
- #elif HAVE_GETTIMEOFDAY
+#elif HAVE_GETTIMEOFDAY
{ struct timeval tv;
if( gettimeofday( &tv, NULL ) )
BUG();
add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 );
add_randomness( &tv.tv_usec, sizeof(tv.tv_usec), 1 );
}
- #elif HAVE_CLOCK_GETTIME
+#elif HAVE_CLOCK_GETTIME
{ struct timespec tv;
if( clock_gettime( CLOCK_REALTIME, &tv ) == -1 )
BUG();
add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 );
add_randomness( &tv.tv_nsec, sizeof(tv.tv_nsec), 1 );
}
- #else /* use times */
- #ifndef HAVE_DOSISH_SYSTEM
+#else /* use times */
+#ifndef HAVE_DOSISH_SYSTEM
{ struct tms buf;
times( &buf );
add_randomness( &buf, sizeof buf, 1 );
}
- #endif
- #endif
- #ifdef HAVE_GETRUSAGE
- #ifndef RUSAGE_SELF
- #ifdef __GCC__
+#endif
+#endif
+#ifdef HAVE_GETRUSAGE
+#ifndef RUSAGE_SELF
+#ifdef __GCC__
#warning There is no RUSAGE_SELF on this system
- #endif
- #else
+#endif
+#else
{
struct rusage buf;
/* QNX/Neutrino does return ENOSYS - so we just ignore it and
@@ -877,8 +882,8 @@ do_fast_random_poll ()
add_randomness( &buf, sizeof buf, 1 );
memset( &buf, 0, sizeof buf );
}
- #endif
- #endif
+#endif
+#endif
/* time and clock are availabe on all systems - so
* we better do it just in case one of the above functions
* didn't work */
diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index d7814cbd..90d0c469 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -1710,7 +1710,7 @@ static const u32 rcon[30] = {
/* Perform the key setup.
*/
-static int
+static gpg_err_code_t
do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
{
static int initialized = 0;
@@ -1728,7 +1728,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
log_error ("%s\n", selftest_failed );
}
if( selftest_failed )
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
if( keylen == 128/8 ) {
ROUNDS = 10;
@@ -1743,7 +1743,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
KC = 8;
}
else
- return GCRYERR_INV_KEYLEN;
+ return GPG_ERR_INV_KEYLEN;
ctx->ROUNDS = ROUNDS;
ctx->decryption_prepared = 0;
@@ -1751,7 +1751,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
for (i = 0; i < keylen; i++) {
k[i >> 2][i & 3] = key[i];
}
- #define W (ctx->keySched)
+#define W (ctx->keySched)
for (j = KC-1; j >= 0; j--) {
*((u32*)tk[j]) = *((u32*)k[j]);
@@ -1806,11 +1806,11 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
}
}
- #undef W
+#undef W
return 0;
}
-static int
+static gpg_err_code_t
rijndael_setkey (void *context, const byte *key, const unsigned keylen)
{
RIJNDAEL_context *ctx = (RIJNDAEL_context *) context;
@@ -1833,7 +1833,7 @@ prepare_decryption( RIJNDAEL_context *ctx )
*((u32*)ctx->keySched2[r][2]) = *((u32*)ctx->keySched[r][2]);
*((u32*)ctx->keySched2[r][3]) = *((u32*)ctx->keySched[r][3]);
}
- #define W (ctx->keySched2)
+#define W (ctx->keySched2)
for (r = 1; r < ctx->ROUNDS; r++) {
w = W[r][0];
*((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
@@ -1851,7 +1851,7 @@ prepare_decryption( RIJNDAEL_context *ctx )
*((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
}
- #undef W
+#undef W
}
@@ -1863,7 +1863,7 @@ do_encrypt (const RIJNDAEL_context *ctx, byte *b, const byte *a)
int r;
byte temp[4][4];
int ROUNDS = ctx->ROUNDS;
- #define rk (ctx->keySched)
+#define rk (ctx->keySched)
*((u32*)temp[0]) = *((u32*)(a )) ^ *((u32*)rk[0][0]);
*((u32*)temp[1]) = *((u32*)(a+ 4)) ^ *((u32*)rk[0][1]);
@@ -1933,7 +1933,7 @@ do_encrypt (const RIJNDAEL_context *ctx, byte *b, const byte *a)
*((u32*)(b+ 4)) ^= *((u32*)rk[ROUNDS][1]);
*((u32*)(b+ 8)) ^= *((u32*)rk[ROUNDS][2]);
*((u32*)(b+12)) ^= *((u32*)rk[ROUNDS][3]);
- #undef rk
+#undef rk
}
static void
@@ -1950,7 +1950,7 @@ rijndael_encrypt (void *context, byte *b, const byte *a)
static void
do_decrypt (RIJNDAEL_context *ctx, byte *b, const byte *a)
{
- #define rk (ctx->keySched2)
+#define rk (ctx->keySched2)
int ROUNDS = ctx->ROUNDS;
int r;
byte temp[4][4];
@@ -2029,7 +2029,7 @@ do_decrypt (RIJNDAEL_context *ctx, byte *b, const byte *a)
*((u32*)(b+ 4)) ^= *((u32*)rk[0][1]);
*((u32*)(b+ 8)) ^= *((u32*)rk[0][2]);
*((u32*)(b+12)) ^= *((u32*)rk[0][3]);
- #undef rk
+#undef rk
}
static void
diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index 23c730f3..ccf630de 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -440,13 +440,13 @@ _gcry_rmd160_mixblock( RMD160_CONTEXT *hd, char *buffer )
{
char *p = buffer;
transform( hd, buffer );
- #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
+#define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
X(0);
X(1);
X(2);
X(3);
X(4);
- #undef X
+#undef X
}
@@ -501,18 +501,18 @@ rmd160_final( void *context )
_gcry_burn_stack (108+5*sizeof(void*));
p = hd->buf;
- #ifdef BIG_ENDIAN_HOST
- #define X(a) do { *p++ = hd->h##a ; *p++ = hd->h##a >> 8; \
+#ifdef BIG_ENDIAN_HOST
+#define X(a) do { *p++ = hd->h##a ; *p++ = hd->h##a >> 8; \
*p++ = hd->h##a >> 16; *p++ = hd->h##a >> 24; } while(0)
- #else /* little endian */
- #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
- #endif
+#else /* little endian */
+#define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
+#endif
X(0);
X(1);
X(2);
X(3);
X(4);
- #undef X
+#undef X
}
static byte *
diff --git a/cipher/rmd160test.c b/cipher/rmd160test.c
index c0cb57f1..7bd11d8e 100644
--- a/cipher/rmd160test.c
+++ b/cipher/rmd160test.c
@@ -45,13 +45,13 @@ main(int argc, char **argv)
usage();
rmdhd = rmd160_open(0);
- #if 1
+#if 1
while( (n = fread( buf, 1, 100, stdin )) > 0 )
rmd160_write(rmdhd, buf, n);
- #else
+#else
for(i=0; i < 1000000; i++ )
rmd160_putchar(rmdhd, 'a');
- #endif
+#endif
p = rmd160_final(rmdhd);
for(i=0; i < 20; i++, p++ )
printf("%02x", *p );
diff --git a/cipher/rndlinux.c b/cipher/rndlinux.c
index 64c84354..cc96fa1f 100644
--- a/cipher/rndlinux.c
+++ b/cipher/rndlinux.c
@@ -28,17 +28,17 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_GETTIMEOFDAY
- #include <sys/times.h>
+#include <sys/times.h>
#endif
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#if 0
- #ifdef HAVE_LINUX_RANDOM_H
- #include <sys/ioctl.h>
- #include <asm/types.h>
- #include <linux/random.h>
- #endif
+#ifdef HAVE_LINUX_RANDOM_H
+#include <sys/ioctl.h>
+#include <asm/types.h>
+#include <linux/random.h>
+#endif
#endif
#include "types.h"
#include "g10lib.h"
@@ -105,11 +105,11 @@ rndlinux_gather_random( void (*add)(const void*, size_t, int), int requester,
fd = fd_urandom;
}
- #if 0
- #ifdef HAVE_DEV_RANDOM_IOCTL
+#if 0
+#ifdef HAVE_DEV_RANDOM_IOCTL
log_info("entropy count of %d is %lu\n", fd, get_entropy_count(fd) );
- #endif
- #endif
+#endif
+#endif
while( length ) {
fd_set rfds;
struct timeval tv;
diff --git a/cipher/rndunix.c b/cipher/rndunix.c
index b9b12c98..fa37d0aa 100644
--- a/cipher/rndunix.c
+++ b/cipher/rndunix.c
@@ -323,9 +323,9 @@ typedef struct {
pid_t
waitpid(pid_t pid, int *statptr, int options)
{
- #ifdef HAVE_WAIT4
+#ifdef HAVE_WAIT4
return wait4(pid, statptr, options, NULL);
- #else
+#else
/* If wait4 is also not available, try wait3 for SVR3 variants */
/* Less ideal because can't actually request a specific pid */
/* For that reason, first check to see if pid is for an */
@@ -341,7 +341,7 @@ waitpid(pid_t pid, int *statptr, int options)
(tmp_pid != -1) && (tmp_pid != 0) && (pid != -1))
;
return tmp_pid;
- #endif
+#endif
}
#endif
@@ -481,11 +481,11 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes )
int moreSources;
struct timeval tv;
fd_set fds;
- #if defined( __hpux )
+#if defined( __hpux )
size_t maxFD = 0;
- #else
+#else
int maxFD = 0;
- #endif /* OS-specific brokenness */
+#endif /* OS-specific brokenness */
int bufPos, i, usefulness = 0;
@@ -539,11 +539,11 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes )
tv.tv_sec = 10;
tv.tv_usec = 0;
- #if defined( __hpux ) && ( OS_VERSION == 9 )
+#if defined( __hpux ) && ( OS_VERSION == 9 )
if (select(maxFD + 1, (int *)&fds, NULL, NULL, &tv) == -1)
- #else /* */
+#else /* */
if (select(maxFD + 1, &fds, NULL, NULL, &tv) == -1)
- #endif /* __hpux */
+#endif /* __hpux */
break;
/* One of the sources has data available, read it into the buffer */
@@ -657,7 +657,7 @@ start_gatherer( int pipefd )
}
/* close all files but the ones we need */
{ int nmax, n1, n2, i;
- #ifdef _SC_OPEN_MAX
+#ifdef _SC_OPEN_MAX
if( (nmax=sysconf( _SC_OPEN_MAX )) < 0 ) {
#ifdef _POSIX_OPEN_MAX
nmax = _POSIX_OPEN_MAX;
@@ -665,9 +665,9 @@ start_gatherer( int pipefd )
nmax = 20; /* assume a reasonable value */
#endif
}
- #else
+#else
nmax = 20; /* assume a reasonable value */
- #endif
+#endif
n1 = fileno( stderr );
n2 = dbgfp? fileno( dbgfp ) : -1;
for(i=0; i < nmax; i++ ) {
@@ -695,11 +695,11 @@ start_gatherer( int pipefd )
* return an error, so the read data won't be added to the randomness
* pool. There are two types of SIGC(H)LD naming, the SysV SIGCLD and
* the BSD/Posix SIGCHLD, so we need to handle either possibility */
- #ifdef SIGCLD
+#ifdef SIGCLD
signal(SIGCLD, SIG_DFL);
- #else
+#else
signal(SIGCHLD, SIG_DFL);
- #endif
+#endif
fclose(stderr); /* Arrghh!! It's Stuart code!! */
diff --git a/cipher/rndw32.c b/cipher/rndw32.c
index c50e0bd1..d7f4ffd2 100644
--- a/cipher/rndw32.c
+++ b/cipher/rndw32.c
@@ -65,7 +65,7 @@
#ifdef IS_MODULE
- #define _(a) (a)
+#define _(a) (a)
#else
/*#include "i18n.h"*/
#endif
@@ -627,7 +627,7 @@ slow_gatherer_windowsNT( void (*add)(const void*, size_t, int), int requester )
CloseHandle (hDevice);
}
- #if 0 /* we don't need this in GnuPG */
+#if 0 /* we don't need this in GnuPG */
/* Wait for any async keyset driver binding to complete. You may be
* wondering what this call is doing here... the reason it's necessary is
* because RegQueryValueEx() will hang indefinitely if the async driver
@@ -647,7 +647,7 @@ slow_gatherer_windowsNT( void (*add)(const void*, size_t, int), int requester )
* this, we have to wait until any async driver bind has completed
* before we can call RegQueryValueEx() */
waitSemaphore (SEMAPHORE_DRIVERBIND);
- #endif
+#endif
/* Get information from the system performance counters. This can take
* a few seconds to do. In some environments the call to
@@ -780,7 +780,7 @@ gather_random_fast( void (*add)(const void*, size_t, int), int requester )
* events in input queue, and milliseconds since Windows was started */
{ byte buffer[20*sizeof(ulong)], *bufptr;
bufptr = buffer;
- #define ADD(f) do { ulong along = (ulong)(f); \
+#define ADD(f) do { ulong along = (ulong)(f); \
memcpy (bufptr, &along, sizeof (along) ); \
bufptr += sizeof (along); } while (0)
ADD ( GetActiveWindow ());
@@ -804,7 +804,7 @@ gather_random_fast( void (*add)(const void*, size_t, int), int requester )
assert ( bufptr-buffer < sizeof (buffer) );
(*add) ( buffer, bufptr-buffer, requester );
- #undef ADD
+#undef ADD
}
/* Get multiword system information: Current caret position, current
diff --git a/cipher/rsa.c b/cipher/rsa.c
index 526686a6..b317f749 100644
--- a/cipher/rsa.c
+++ b/cipher/rsa.c
@@ -33,28 +33,30 @@
#include "cipher.h"
-typedef struct {
- MPI n; /* modulus */
- MPI e; /* exponent */
+typedef struct
+{
+ MPI n; /* modulus */
+ MPI e; /* exponent */
} RSA_public_key;
-typedef struct {
- MPI n; /* public modulus */
- MPI e; /* public exponent */
- MPI d; /* exponent */
- MPI p; /* prime p. */
- MPI q; /* prime q. */
- MPI u; /* inverse of p mod q. */
+typedef struct
+{
+ MPI n; /* public modulus */
+ MPI e; /* public exponent */
+ MPI d; /* exponent */
+ MPI p; /* prime p. */
+ MPI q; /* prime q. */
+ MPI u; /* inverse of p mod q. */
} RSA_secret_key;
-static void test_keys( RSA_secret_key *sk, unsigned nbits );
+static void test_keys (RSA_secret_key *sk, unsigned nbits);
static void generate (RSA_secret_key *sk,
- unsigned int nbits, unsigned long use_e );
-static int check_secret_key( RSA_secret_key *sk );
-static void public(MPI output, MPI input, RSA_public_key *skey );
-static void secret(MPI output, MPI input, RSA_secret_key *skey );
+ unsigned int nbits, unsigned long use_e);
+static int check_secret_key (RSA_secret_key *sk);
+static void public (MPI output, MPI input, RSA_public_key *skey);
+static void secret (MPI output, MPI input, RSA_secret_key *skey);
static void
@@ -349,9 +351,9 @@ stronger_key_check ( RSA_secret_key *skey )
static void
secret(MPI output, MPI input, RSA_secret_key *skey )
{
- #if 0
+#if 0
mpi_powm( output, input, skey->d, skey->n );
- #else
+#else
MPI m1 = mpi_alloc_secure( mpi_get_nlimbs(skey->n)+1 );
MPI m2 = mpi_alloc_secure( mpi_get_nlimbs(skey->n)+1 );
MPI h = mpi_alloc_secure( mpi_get_nlimbs(skey->n)+1 );
@@ -377,7 +379,7 @@ secret(MPI output, MPI input, RSA_secret_key *skey )
mpi_free ( h );
mpi_free ( m1 );
mpi_free ( m2 );
- #endif
+#endif
}
@@ -386,75 +388,70 @@ secret(MPI output, MPI input, RSA_secret_key *skey )
************** interface ******************
*********************************************/
-int
+gpg_err_code_t
_gcry_rsa_generate (int algo, unsigned int nbits, unsigned long use_e,
MPI *skey, MPI **retfactors)
{
- RSA_secret_key sk;
-
- if( !is_RSA(algo) )
- return GCRYERR_INV_PK_ALGO;
-
- generate( &sk, nbits, use_e );
- skey[0] = sk.n;
- skey[1] = sk.e;
- skey[2] = sk.d;
- skey[3] = sk.p;
- skey[4] = sk.q;
- skey[5] = sk.u;
- /* make an empty list of factors */
- *retfactors = gcry_xcalloc( 1, sizeof **retfactors );
- return 0;
+ RSA_secret_key sk;
+
+ generate (&sk, nbits, use_e);
+ skey[0] = sk.n;
+ skey[1] = sk.e;
+ skey[2] = sk.d;
+ skey[3] = sk.p;
+ skey[4] = sk.q;
+ skey[5] = sk.u;
+
+ /* make an empty list of factors */
+ *retfactors = gcry_xcalloc( 1, sizeof **retfactors );
+
+ return GPG_ERR_NO_ERROR;
}
-int
+gpg_err_code_t
_gcry_rsa_check_secret_key( int algo, MPI *skey )
{
- RSA_secret_key sk;
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ RSA_secret_key sk;
- if( !is_RSA(algo) )
- return GCRYERR_INV_PK_ALGO;
+ sk.n = skey[0];
+ sk.e = skey[1];
+ sk.d = skey[2];
+ sk.p = skey[3];
+ sk.q = skey[4];
+ sk.u = skey[5];
- sk.n = skey[0];
- sk.e = skey[1];
- sk.d = skey[2];
- sk.p = skey[3];
- sk.q = skey[4];
- sk.u = skey[5];
- if( !check_secret_key( &sk ) )
- return GCRYERR_INV_PK_ALGO;
+ if (! check_secret_key (&sk))
+ err = GPG_ERR_PUBKEY_ALGO;
- return 0;
+ return err;
}
-
-int
+gpg_err_code_t
_gcry_rsa_encrypt (int algo, MPI *resarr, MPI data, MPI *pkey,
int flags)
{
- RSA_public_key pk;
+ RSA_public_key pk;
- if( algo != 1 && algo != 2 )
- return GCRYERR_INV_PK_ALGO;
+ pk.n = pkey[0];
+ pk.e = pkey[1];
+ resarr[0] = mpi_alloc (mpi_get_nlimbs (pk.n));
+ public (resarr[0], data, &pk);
- pk.n = pkey[0];
- pk.e = pkey[1];
- resarr[0] = mpi_alloc( mpi_get_nlimbs( pk.n ) );
- public( resarr[0], data, &pk );
- return 0;
+ return GPG_ERR_NO_ERROR;
}
/* Perform RSA blinding. */
-GcryMPI
+gcry_mpi_t
_gcry_rsa_blind (MPI x, MPI r, MPI e, MPI n)
{
/* A helper. */
- GcryMPI a;
+ gcry_mpi_t a;
/* Result. */
- GcryMPI y;
+ gcry_mpi_t y;
a = gcry_mpi_snew (gcry_mpi_get_nbits (n));
y = gcry_mpi_snew (gcry_mpi_get_nbits (n));
@@ -471,10 +468,10 @@ _gcry_rsa_blind (MPI x, MPI r, MPI e, MPI n)
}
/* Undo RSA blinding. */
-GcryMPI
+gcry_mpi_t
_gcry_rsa_unblind (MPI x, MPI ri, MPI n)
{
- GcryMPI y;
+ gcry_mpi_t y;
y = gcry_mpi_snew (gcry_mpi_get_nbits (n));
@@ -487,133 +484,123 @@ _gcry_rsa_unblind (MPI x, MPI ri, MPI n)
return y;
}
-int
+gpg_err_code_t
_gcry_rsa_decrypt (int algo, MPI *result, MPI *data, MPI *skey,
int flags)
{
- RSA_secret_key sk;
- GcryMPI r = MPI_NULL; /* Random number needed for
- blinding. */
- GcryMPI ri = MPI_NULL; /* Modular multiplicative inverse of
+ RSA_secret_key sk;
+ gcry_mpi_t r = MPI_NULL; /* Random number needed for blinding. */
+ gcry_mpi_t ri = MPI_NULL; /* Modular multiplicative inverse of
r. */
- GcryMPI x = MPI_NULL; /* Data to decrypt. */
- GcryMPI y; /* Result. */
+ gcry_mpi_t x = MPI_NULL; /* Data to decrypt. */
+ gcry_mpi_t y; /* Result. */
- if (algo != 1 && algo != 2)
- return GCRYERR_INV_PK_ALGO;
+ /* Extract private key. */
+ sk.n = skey[0];
+ sk.e = skey[1];
+ sk.d = skey[2];
+ sk.p = skey[3];
+ sk.q = skey[4];
+ sk.u = skey[5];
- /* Extract private key. */
- sk.n = skey[0];
- sk.e = skey[1];
- sk.d = skey[2];
- sk.p = skey[3];
- sk.q = skey[4];
- sk.u = skey[5];
+ y = gcry_mpi_snew (gcry_mpi_get_nbits (sk.n));
- y = gcry_mpi_snew (gcry_mpi_get_nbits (sk.n));
-
- if (! (flags & PUBKEY_FLAG_NO_BLINDING))
- {
- /* Initialize blinding. */
-
- /* First, we need a random number r between 0 and n - 1, which
- is relatively prime to n (i.e. it is neither p nor q). */
- r = gcry_mpi_snew (gcry_mpi_get_nbits (sk.n));
- ri = gcry_mpi_snew (gcry_mpi_get_nbits (sk.n));
-
- gcry_mpi_randomize (r, gcry_mpi_get_nbits (sk.n),
- GCRY_STRONG_RANDOM);
- gcry_mpi_mod (r, r, sk.n);
-
- /* Actually it should be okay to skip the check for equality
- with either p or q here. */
-
- /* Calculate inverse of r. */
- if (! gcry_mpi_invm (ri, r, sk.n))
- BUG ();
- }
-
- if (! (flags & PUBKEY_FLAG_NO_BLINDING))
- /* Do blinding. */
- x = _gcry_rsa_blind (data[0], r, sk.e, sk.n);
- else
- /* Skip blinding. */
- x = data[0];
-
- /* Do the encryption. */
- secret (y, x, &sk);
+ if (! (flags & PUBKEY_FLAG_NO_BLINDING))
+ {
+ /* Initialize blinding. */
+
+ /* First, we need a random number r between 0 and n - 1, which
+ is relatively prime to n (i.e. it is neither p nor q). */
+ r = gcry_mpi_snew (gcry_mpi_get_nbits (sk.n));
+ ri = gcry_mpi_snew (gcry_mpi_get_nbits (sk.n));
+
+ gcry_mpi_randomize (r, gcry_mpi_get_nbits (sk.n),
+ GCRY_STRONG_RANDOM);
+ gcry_mpi_mod (r, r, sk.n);
+
+ /* Actually it should be okay to skip the check for equality
+ with either p or q here. */
+
+ /* Calculate inverse of r. */
+ if (! gcry_mpi_invm (ri, r, sk.n))
+ BUG ();
+ }
- if (! (flags & PUBKEY_FLAG_NO_BLINDING))
- {
- /* Undo blinding. */
- GcryMPI a = gcry_mpi_copy (y);
+ if (! (flags & PUBKEY_FLAG_NO_BLINDING))
+ /* Do blinding. */
+ x = _gcry_rsa_blind (data[0], r, sk.e, sk.n);
+ else
+ /* Skip blinding. */
+ x = data[0];
- gcry_mpi_release (y);
- y = _gcry_rsa_unblind (a, ri, sk.n);
- }
+ /* Do the encryption. */
+ secret (y, x, &sk);
- if (! (flags & PUBKEY_FLAG_NO_BLINDING))
- {
- /* Deallocate resources needed for blinding. */
- gcry_mpi_release (x);
- gcry_mpi_release (r);
- gcry_mpi_release (ri);
- }
+ if (! (flags & PUBKEY_FLAG_NO_BLINDING))
+ {
+ /* Undo blinding. */
+ gcry_mpi_t a = gcry_mpi_copy (y);
+
+ gcry_mpi_release (y);
+ y = _gcry_rsa_unblind (a, ri, sk.n);
+ }
- /* Copy out result. */
- *result = y;
+ if (! (flags & PUBKEY_FLAG_NO_BLINDING))
+ {
+ /* Deallocate resources needed for blinding. */
+ gcry_mpi_release (x);
+ gcry_mpi_release (r);
+ gcry_mpi_release (ri);
+ }
- return 0;
+ /* Copy out result. */
+ *result = y;
+
+ return GPG_ERR_NO_ERROR;
}
-int
-_gcry_rsa_sign( int algo, MPI *resarr, MPI data, MPI *skey )
+gpg_err_code_t
+_gcry_rsa_sign (int algo, MPI *resarr, MPI data, MPI *skey)
{
- RSA_secret_key sk;
-
- if( algo != 1 && algo != 3 )
- return GCRYERR_INV_PK_ALGO;
-
- sk.n = skey[0];
- sk.e = skey[1];
- sk.d = skey[2];
- sk.p = skey[3];
- sk.q = skey[4];
- sk.u = skey[5];
- resarr[0] = mpi_alloc( mpi_get_nlimbs( sk.n ) );
- secret( resarr[0], data, &sk );
-
- return 0;
+ RSA_secret_key sk;
+
+ sk.n = skey[0];
+ sk.e = skey[1];
+ sk.d = skey[2];
+ sk.p = skey[3];
+ sk.q = skey[4];
+ sk.u = skey[5];
+ resarr[0] = mpi_alloc( mpi_get_nlimbs (sk.n));
+ secret (resarr[0], data, &sk);
+
+ return GPG_ERR_NO_ERROR;
}
-int
-_gcry_rsa_verify( int algo, MPI hash, MPI *data, MPI *pkey,
- int (*cmp)(void *opaque, MPI tmp), void *opaquev )
+gpg_err_code_t
+_gcry_rsa_verify (int algo, MPI hash, MPI *data, MPI *pkey,
+ int (*cmp) (void *opaque, MPI tmp),
+ void *opaquev)
{
- RSA_public_key pk;
- MPI result;
- int rc;
-
- if( algo != 1 && algo != 3 )
- return GCRYERR_INV_PK_ALGO;
- pk.n = pkey[0];
- pk.e = pkey[1];
- result = gcry_mpi_new ( 160 );
- public( result, data[0], &pk );
- /*rc = (*cmp)( opaquev, result );*/
- rc = mpi_cmp( result, hash )? GCRYERR_BAD_SIGNATURE:0;
- gcry_mpi_release (result);
-
- return rc;
+ RSA_public_key pk;
+ MPI result;
+ gpg_err_code_t rc;
+
+ pk.n = pkey[0];
+ pk.e = pkey[1];
+ result = gcry_mpi_new ( 160 );
+ public( result, data[0], &pk );
+ /*rc = (*cmp)( opaquev, result );*/
+ rc = mpi_cmp (result, hash) ? GPG_ERR_BAD_SIGNATURE : GPG_ERR_NO_ERROR;
+ gcry_mpi_release (result);
+
+ return rc;
}
unsigned int
-_gcry_rsa_get_nbits( int algo, MPI *pkey )
+_gcry_rsa_get_nbits (int algo, MPI *pkey)
{
- if( !is_RSA(algo) )
- return 0;
- return mpi_get_nbits( pkey[0] );
+ return mpi_get_nbits (pkey[0]);
}
static char *rsa_names[] =
diff --git a/cipher/sha1.c b/cipher/sha1.c
index cacbd829..bc284c42 100644
--- a/cipher/sha1.c
+++ b/cipher/sha1.c
@@ -77,9 +77,9 @@ transform( SHA1_CONTEXT *hd, byte *data )
d = hd->h3;
e = hd->h4;
- #ifdef BIG_ENDIAN_HOST
+#ifdef BIG_ENDIAN_HOST
memcpy( x, data, 64 );
- #else
+#else
{ int i;
byte *p2;
for(i=0, p2=(byte*)x; i < 16; i++, p2 += 4 ) {
@@ -89,7 +89,7 @@ transform( SHA1_CONTEXT *hd, byte *data )
p2[0] = *data++;
}
}
- #endif
+#endif
#define K1 0x5A827999L
@@ -293,18 +293,18 @@ sha1_final(void *context)
_gcry_burn_stack (88+4*sizeof(void*));
p = hd->buf;
- #ifdef BIG_ENDIAN_HOST
- #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
- #else /* little endian */
- #define X(a) do { *p++ = hd->h##a >> 24; *p++ = hd->h##a >> 16; \
+#ifdef BIG_ENDIAN_HOST
+#define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
+#else /* little endian */
+#define X(a) do { *p++ = hd->h##a >> 24; *p++ = hd->h##a >> 16; \
*p++ = hd->h##a >> 8; *p++ = hd->h##a; } while(0)
- #endif
+#endif
X(0);
X(1);
X(2);
X(3);
X(4);
- #undef X
+#undef X
}
diff --git a/cipher/sha512.c b/cipher/sha512.c
index 2a6f7a0f..c731eae1 100644
--- a/cipher/sha512.c
+++ b/cipher/sha512.c
@@ -68,14 +68,14 @@ sha512_init (void *context)
{
SHA512_CONTEXT *hd = (SHA512_CONTEXT *) context;
- hd->h0 = 0x6a09e667f3bcc908;
- hd->h1 = 0xbb67ae8584caa73b;
- hd->h2 = 0x3c6ef372fe94f82b;
- hd->h3 = 0xa54ff53a5f1d36f1;
- hd->h4 = 0x510e527fade682d1;
- hd->h5 = 0x9b05688c2b3e6c1f;
- hd->h6 = 0x1f83d9abfb41bd6b;
- hd->h7 = 0x5be0cd19137e2179;
+ hd->h0 = U64_C(0x6a09e667f3bcc908);
+ hd->h1 = U64_C(0xbb67ae8584caa73b);
+ hd->h2 = U64_C(0x3c6ef372fe94f82b);
+ hd->h3 = U64_C(0xa54ff53a5f1d36f1);
+ hd->h4 = U64_C(0x510e527fade682d1);
+ hd->h5 = U64_C(0x9b05688c2b3e6c1f);
+ hd->h6 = U64_C(0x1f83d9abfb41bd6b);
+ hd->h7 = U64_C(0x5be0cd19137e2179);
hd->nblocks = 0;
hd->count = 0;
@@ -86,14 +86,14 @@ sha384_init (void *context)
{
SHA512_CONTEXT *hd = (SHA512_CONTEXT *) context;
- hd->h0 = 0xcbbb9d5dc1059ed8;
- hd->h1 = 0x629a292a367cd507;
- hd->h2 = 0x9159015a3070dd17;
- hd->h3 = 0x152fecd8f70e5939;
- hd->h4 = 0x67332667ffc00b31;
- hd->h5 = 0x8eb44a8768581511;
- hd->h6 = 0xdb0c2e0d64f98fa7;
- hd->h7 = 0x47b5481dbefa4fa4;
+ hd->h0 = U64_C(0xcbbb9d5dc1059ed8);
+ hd->h1 = U64_C(0x629a292a367cd507);
+ hd->h2 = U64_C(0x9159015a3070dd17);
+ hd->h3 = U64_C(0x152fecd8f70e5939);
+ hd->h4 = U64_C(0x67332667ffc00b31);
+ hd->h5 = U64_C(0x8eb44a8768581511);
+ hd->h6 = U64_C(0xdb0c2e0d64f98fa7);
+ hd->h7 = U64_C(0x47b5481dbefa4fa4);
hd->nblocks = 0;
hd->count = 0;
@@ -111,33 +111,46 @@ transform (SHA512_CONTEXT *hd, byte *data)
int t;
static const u64 k[] =
{
- 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f,
- 0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019,
- 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242,
- 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2,
- 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235,
- 0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3,
- 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, 0x2de92c6f592b0275,
- 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5,
- 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f,
- 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725,
- 0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc,
- 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df,
- 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6,
- 0x92722c851482353b, 0xa2bfe8a14cf10364, 0xa81a664bbc423001,
- 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218,
- 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8,
- 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99,
- 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb,
- 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc,
- 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,
- 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915,
- 0xc67178f2e372532b, 0xca273eceea26619c, 0xd186b8c721c0c207,
- 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba,
- 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b,
- 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc,
- 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a,
- 0x5fcb6fab3ad6faec, 0x6c44198c4a475817
+ U64_C(0x428a2f98d728ae22), U64_C(0x7137449123ef65cd),
+ U64_C(0xb5c0fbcfec4d3b2f), U64_C(0xe9b5dba58189dbbc),
+ U64_C(0x3956c25bf348b538), U64_C(0x59f111f1b605d019),
+ U64_C(0x923f82a4af194f9b), U64_C(0xab1c5ed5da6d8118),
+ U64_C(0xd807aa98a3030242), U64_C(0x12835b0145706fbe),
+ U64_C(0x243185be4ee4b28c), U64_C(0x550c7dc3d5ffb4e2),
+ U64_C(0x72be5d74f27b896f), U64_C(0x80deb1fe3b1696b1),
+ U64_C(0x9bdc06a725c71235), U64_C(0xc19bf174cf692694),
+ U64_C(0xe49b69c19ef14ad2), U64_C(0xefbe4786384f25e3),
+ U64_C(0x0fc19dc68b8cd5b5), U64_C(0x240ca1cc77ac9c65),
+ U64_C(0x2de92c6f592b0275), U64_C(0x4a7484aa6ea6e483),
+ U64_C(0x5cb0a9dcbd41fbd4), U64_C(0x76f988da831153b5),
+ U64_C(0x983e5152ee66dfab), U64_C(0xa831c66d2db43210),
+ U64_C(0xb00327c898fb213f), U64_C(0xbf597fc7beef0ee4),
+ U64_C(0xc6e00bf33da88fc2), U64_C(0xd5a79147930aa725),
+ U64_C(0x06ca6351e003826f), U64_C(0x142929670a0e6e70),
+ U64_C(0x27b70a8546d22ffc), U64_C(0x2e1b21385c26c926),
+ U64_C(0x4d2c6dfc5ac42aed), U64_C(0x53380d139d95b3df),
+ U64_C(0x650a73548baf63de), U64_C(0x766a0abb3c77b2a8),
+ U64_C(0x81c2c92e47edaee6), U64_C(0x92722c851482353b),
+ U64_C(0xa2bfe8a14cf10364), U64_C(0xa81a664bbc423001),
+ U64_C(0xc24b8b70d0f89791), U64_C(0xc76c51a30654be30),
+ U64_C(0xd192e819d6ef5218), U64_C(0xd69906245565a910),
+ U64_C(0xf40e35855771202a), U64_C(0x106aa07032bbd1b8),
+ U64_C(0x19a4c116b8d2d0c8), U64_C(0x1e376c085141ab53),
+ U64_C(0x2748774cdf8eeb99), U64_C(0x34b0bcb5e19b48a8),
+ U64_C(0x391c0cb3c5c95a63), U64_C(0x4ed8aa4ae3418acb),
+ U64_C(0x5b9cca4f7763e373), U64_C(0x682e6ff3d6b2b8a3),
+ U64_C(0x748f82ee5defb2fc), U64_C(0x78a5636f43172f60),
+ U64_C(0x84c87814a1f0ab72), U64_C(0x8cc702081a6439ec),
+ U64_C(0x90befffa23631e28), U64_C(0xa4506cebde82bde9),
+ U64_C(0xbef9a3f7b2c67915), U64_C(0xc67178f2e372532b),
+ U64_C(0xca273eceea26619c), U64_C(0xd186b8c721c0c207),
+ U64_C(0xeada7dd6cde0eb1e), U64_C(0xf57d4f7fee6ed178),
+ U64_C(0x06f067aa72176fba), U64_C(0x0a637dc5a2c898a6),
+ U64_C(0x113f9804bef90dae), U64_C(0x1b710b35131c471b),
+ U64_C(0x28db77f523047d84), U64_C(0x32caab7b40c72493),
+ U64_C(0x3c9ebe0a15c9bebc), U64_C(0x431d67c49c100d4c),
+ U64_C(0x4cc5d4becb3e42b6), U64_C(0x597f299cfc657e2a),
+ U64_C(0x5fcb6fab3ad6faec), U64_C(0x6c44198c4a475817)
};
/* get values from the chaining vars */
diff --git a/cipher/tiger.c b/cipher/tiger.c
index af0fdd78..f8e6f938 100644
--- a/cipher/tiger.c
+++ b/cipher/tiger.c
@@ -66,530 +66,527 @@ typedef struct {
* 00B83EB4E53440C5 76AC6AAEE0A74858 25FD15E70A59FFE4
*/
-
static u64 sbox1[256] = {
- 0x02aab17cf7e90c5eLL /* 0 */, 0xac424b03e243a8ecLL /* 1 */,
- 0x72cd5be30dd5fcd3LL /* 2 */, 0x6d019b93f6f97f3aLL /* 3 */,
- 0xcd9978ffd21f9193LL /* 4 */, 0x7573a1c9708029e2LL /* 5 */,
- 0xb164326b922a83c3LL /* 6 */, 0x46883eee04915870LL /* 7 */,
- 0xeaace3057103ece6LL /* 8 */, 0xc54169b808a3535cLL /* 9 */,
- 0x4ce754918ddec47cLL /* 10 */, 0x0aa2f4dfdc0df40cLL /* 11 */,
- 0x10b76f18a74dbefaLL /* 12 */, 0xc6ccb6235ad1ab6aLL /* 13 */,
- 0x13726121572fe2ffLL /* 14 */, 0x1a488c6f199d921eLL /* 15 */,
- 0x4bc9f9f4da0007caLL /* 16 */, 0x26f5e6f6e85241c7LL /* 17 */,
- 0x859079dbea5947b6LL /* 18 */, 0x4f1885c5c99e8c92LL /* 19 */,
- 0xd78e761ea96f864bLL /* 20 */, 0x8e36428c52b5c17dLL /* 21 */,
- 0x69cf6827373063c1LL /* 22 */, 0xb607c93d9bb4c56eLL /* 23 */,
- 0x7d820e760e76b5eaLL /* 24 */, 0x645c9cc6f07fdc42LL /* 25 */,
- 0xbf38a078243342e0LL /* 26 */, 0x5f6b343c9d2e7d04LL /* 27 */,
- 0xf2c28aeb600b0ec6LL /* 28 */, 0x6c0ed85f7254bcacLL /* 29 */,
- 0x71592281a4db4fe5LL /* 30 */, 0x1967fa69ce0fed9fLL /* 31 */,
- 0xfd5293f8b96545dbLL /* 32 */, 0xc879e9d7f2a7600bLL /* 33 */,
- 0x860248920193194eLL /* 34 */, 0xa4f9533b2d9cc0b3LL /* 35 */,
- 0x9053836c15957613LL /* 36 */, 0xdb6dcf8afc357bf1LL /* 37 */,
- 0x18beea7a7a370f57LL /* 38 */, 0x037117ca50b99066LL /* 39 */,
- 0x6ab30a9774424a35LL /* 40 */, 0xf4e92f02e325249bLL /* 41 */,
- 0x7739db07061ccae1LL /* 42 */, 0xd8f3b49ceca42a05LL /* 43 */,
- 0xbd56be3f51382f73LL /* 44 */, 0x45faed5843b0bb28LL /* 45 */,
- 0x1c813d5c11bf1f83LL /* 46 */, 0x8af0e4b6d75fa169LL /* 47 */,
- 0x33ee18a487ad9999LL /* 48 */, 0x3c26e8eab1c94410LL /* 49 */,
- 0xb510102bc0a822f9LL /* 50 */, 0x141eef310ce6123bLL /* 51 */,
- 0xfc65b90059ddb154LL /* 52 */, 0xe0158640c5e0e607LL /* 53 */,
- 0x884e079826c3a3cfLL /* 54 */, 0x930d0d9523c535fdLL /* 55 */,
- 0x35638d754e9a2b00LL /* 56 */, 0x4085fccf40469dd5LL /* 57 */,
- 0xc4b17ad28be23a4cLL /* 58 */, 0xcab2f0fc6a3e6a2eLL /* 59 */,
- 0x2860971a6b943fcdLL /* 60 */, 0x3dde6ee212e30446LL /* 61 */,
- 0x6222f32ae01765aeLL /* 62 */, 0x5d550bb5478308feLL /* 63 */,
- 0xa9efa98da0eda22aLL /* 64 */, 0xc351a71686c40da7LL /* 65 */,
- 0x1105586d9c867c84LL /* 66 */, 0xdcffee85fda22853LL /* 67 */,
- 0xccfbd0262c5eef76LL /* 68 */, 0xbaf294cb8990d201LL /* 69 */,
- 0xe69464f52afad975LL /* 70 */, 0x94b013afdf133e14LL /* 71 */,
- 0x06a7d1a32823c958LL /* 72 */, 0x6f95fe5130f61119LL /* 73 */,
- 0xd92ab34e462c06c0LL /* 74 */, 0xed7bde33887c71d2LL /* 75 */,
- 0x79746d6e6518393eLL /* 76 */, 0x5ba419385d713329LL /* 77 */,
- 0x7c1ba6b948a97564LL /* 78 */, 0x31987c197bfdac67LL /* 79 */,
- 0xde6c23c44b053d02LL /* 80 */, 0x581c49fed002d64dLL /* 81 */,
- 0xdd474d6338261571LL /* 82 */, 0xaa4546c3e473d062LL /* 83 */,
- 0x928fce349455f860LL /* 84 */, 0x48161bbacaab94d9LL /* 85 */,
- 0x63912430770e6f68LL /* 86 */, 0x6ec8a5e602c6641cLL /* 87 */,
- 0x87282515337ddd2bLL /* 88 */, 0x2cda6b42034b701bLL /* 89 */,
- 0xb03d37c181cb096dLL /* 90 */, 0xe108438266c71c6fLL /* 91 */,
- 0x2b3180c7eb51b255LL /* 92 */, 0xdf92b82f96c08bbcLL /* 93 */,
- 0x5c68c8c0a632f3baLL /* 94 */, 0x5504cc861c3d0556LL /* 95 */,
- 0xabbfa4e55fb26b8fLL /* 96 */, 0x41848b0ab3baceb4LL /* 97 */,
- 0xb334a273aa445d32LL /* 98 */, 0xbca696f0a85ad881LL /* 99 */,
- 0x24f6ec65b528d56cLL /* 100 */, 0x0ce1512e90f4524aLL /* 101 */,
- 0x4e9dd79d5506d35aLL /* 102 */, 0x258905fac6ce9779LL /* 103 */,
- 0x2019295b3e109b33LL /* 104 */, 0xf8a9478b73a054ccLL /* 105 */,
- 0x2924f2f934417eb0LL /* 106 */, 0x3993357d536d1bc4LL /* 107 */,
- 0x38a81ac21db6ff8bLL /* 108 */, 0x47c4fbf17d6016bfLL /* 109 */,
- 0x1e0faadd7667e3f5LL /* 110 */, 0x7abcff62938beb96LL /* 111 */,
- 0xa78dad948fc179c9LL /* 112 */, 0x8f1f98b72911e50dLL /* 113 */,
- 0x61e48eae27121a91LL /* 114 */, 0x4d62f7ad31859808LL /* 115 */,
- 0xeceba345ef5ceaebLL /* 116 */, 0xf5ceb25ebc9684ceLL /* 117 */,
- 0xf633e20cb7f76221LL /* 118 */, 0xa32cdf06ab8293e4LL /* 119 */,
- 0x985a202ca5ee2ca4LL /* 120 */, 0xcf0b8447cc8a8fb1LL /* 121 */,
- 0x9f765244979859a3LL /* 122 */, 0xa8d516b1a1240017LL /* 123 */,
- 0x0bd7ba3ebb5dc726LL /* 124 */, 0xe54bca55b86adb39LL /* 125 */,
- 0x1d7a3afd6c478063LL /* 126 */, 0x519ec608e7669eddLL /* 127 */,
- 0x0e5715a2d149aa23LL /* 128 */, 0x177d4571848ff194LL /* 129 */,
- 0xeeb55f3241014c22LL /* 130 */, 0x0f5e5ca13a6e2ec2LL /* 131 */,
- 0x8029927b75f5c361LL /* 132 */, 0xad139fabc3d6e436LL /* 133 */,
- 0x0d5df1a94ccf402fLL /* 134 */, 0x3e8bd948bea5dfc8LL /* 135 */,
- 0xa5a0d357bd3ff77eLL /* 136 */, 0xa2d12e251f74f645LL /* 137 */,
- 0x66fd9e525e81a082LL /* 138 */, 0x2e0c90ce7f687a49LL /* 139 */,
- 0xc2e8bcbeba973bc5LL /* 140 */, 0x000001bce509745fLL /* 141 */,
- 0x423777bbe6dab3d6LL /* 142 */, 0xd1661c7eaef06eb5LL /* 143 */,
- 0xa1781f354daacfd8LL /* 144 */, 0x2d11284a2b16affcLL /* 145 */,
- 0xf1fc4f67fa891d1fLL /* 146 */, 0x73ecc25dcb920adaLL /* 147 */,
- 0xae610c22c2a12651LL /* 148 */, 0x96e0a810d356b78aLL /* 149 */,
- 0x5a9a381f2fe7870fLL /* 150 */, 0xd5ad62ede94e5530LL /* 151 */,
- 0xd225e5e8368d1427LL /* 152 */, 0x65977b70c7af4631LL /* 153 */,
- 0x99f889b2de39d74fLL /* 154 */, 0x233f30bf54e1d143LL /* 155 */,
- 0x9a9675d3d9a63c97LL /* 156 */, 0x5470554ff334f9a8LL /* 157 */,
- 0x166acb744a4f5688LL /* 158 */, 0x70c74caab2e4aeadLL /* 159 */,
- 0xf0d091646f294d12LL /* 160 */, 0x57b82a89684031d1LL /* 161 */,
- 0xefd95a5a61be0b6bLL /* 162 */, 0x2fbd12e969f2f29aLL /* 163 */,
- 0x9bd37013feff9fe8LL /* 164 */, 0x3f9b0404d6085a06LL /* 165 */,
- 0x4940c1f3166cfe15LL /* 166 */, 0x09542c4dcdf3defbLL /* 167 */,
- 0xb4c5218385cd5ce3LL /* 168 */, 0xc935b7dc4462a641LL /* 169 */,
- 0x3417f8a68ed3b63fLL /* 170 */, 0xb80959295b215b40LL /* 171 */,
- 0xf99cdaef3b8c8572LL /* 172 */, 0x018c0614f8fcb95dLL /* 173 */,
- 0x1b14accd1a3acdf3LL /* 174 */, 0x84d471f200bb732dLL /* 175 */,
- 0xc1a3110e95e8da16LL /* 176 */, 0x430a7220bf1a82b8LL /* 177 */,
- 0xb77e090d39df210eLL /* 178 */, 0x5ef4bd9f3cd05e9dLL /* 179 */,
- 0x9d4ff6da7e57a444LL /* 180 */, 0xda1d60e183d4a5f8LL /* 181 */,
- 0xb287c38417998e47LL /* 182 */, 0xfe3edc121bb31886LL /* 183 */,
- 0xc7fe3ccc980ccbefLL /* 184 */, 0xe46fb590189bfd03LL /* 185 */,
- 0x3732fd469a4c57dcLL /* 186 */, 0x7ef700a07cf1ad65LL /* 187 */,
- 0x59c64468a31d8859LL /* 188 */, 0x762fb0b4d45b61f6LL /* 189 */,
- 0x155baed099047718LL /* 190 */, 0x68755e4c3d50baa6LL /* 191 */,
- 0xe9214e7f22d8b4dfLL /* 192 */, 0x2addbf532eac95f4LL /* 193 */,
- 0x32ae3909b4bd0109LL /* 194 */, 0x834df537b08e3450LL /* 195 */,
- 0xfa209da84220728dLL /* 196 */, 0x9e691d9b9efe23f7LL /* 197 */,
- 0x0446d288c4ae8d7fLL /* 198 */, 0x7b4cc524e169785bLL /* 199 */,
- 0x21d87f0135ca1385LL /* 200 */, 0xcebb400f137b8aa5LL /* 201 */,
- 0x272e2b66580796beLL /* 202 */, 0x3612264125c2b0deLL /* 203 */,
- 0x057702bdad1efbb2LL /* 204 */, 0xd4babb8eacf84be9LL /* 205 */,
- 0x91583139641bc67bLL /* 206 */, 0x8bdc2de08036e024LL /* 207 */,
- 0x603c8156f49f68edLL /* 208 */, 0xf7d236f7dbef5111LL /* 209 */,
- 0x9727c4598ad21e80LL /* 210 */, 0xa08a0896670a5fd7LL /* 211 */,
- 0xcb4a8f4309eba9cbLL /* 212 */, 0x81af564b0f7036a1LL /* 213 */,
- 0xc0b99aa778199abdLL /* 214 */, 0x959f1ec83fc8e952LL /* 215 */,
- 0x8c505077794a81b9LL /* 216 */, 0x3acaaf8f056338f0LL /* 217 */,
- 0x07b43f50627a6778LL /* 218 */, 0x4a44ab49f5eccc77LL /* 219 */,
- 0x3bc3d6e4b679ee98LL /* 220 */, 0x9cc0d4d1cf14108cLL /* 221 */,
- 0x4406c00b206bc8a0LL /* 222 */, 0x82a18854c8d72d89LL /* 223 */,
- 0x67e366b35c3c432cLL /* 224 */, 0xb923dd61102b37f2LL /* 225 */,
- 0x56ab2779d884271dLL /* 226 */, 0xbe83e1b0ff1525afLL /* 227 */,
- 0xfb7c65d4217e49a9LL /* 228 */, 0x6bdbe0e76d48e7d4LL /* 229 */,
- 0x08df828745d9179eLL /* 230 */, 0x22ea6a9add53bd34LL /* 231 */,
- 0xe36e141c5622200aLL /* 232 */, 0x7f805d1b8cb750eeLL /* 233 */,
- 0xafe5c7a59f58e837LL /* 234 */, 0xe27f996a4fb1c23cLL /* 235 */,
- 0xd3867dfb0775f0d0LL /* 236 */, 0xd0e673de6e88891aLL /* 237 */,
- 0x123aeb9eafb86c25LL /* 238 */, 0x30f1d5d5c145b895LL /* 239 */,
- 0xbb434a2dee7269e7LL /* 240 */, 0x78cb67ecf931fa38LL /* 241 */,
- 0xf33b0372323bbf9cLL /* 242 */, 0x52d66336fb279c74LL /* 243 */,
- 0x505f33ac0afb4eaaLL /* 244 */, 0xe8a5cd99a2cce187LL /* 245 */,
- 0x534974801e2d30bbLL /* 246 */, 0x8d2d5711d5876d90LL /* 247 */,
- 0x1f1a412891bc038eLL /* 248 */, 0xd6e2e71d82e56648LL /* 249 */,
- 0x74036c3a497732b7LL /* 250 */, 0x89b67ed96361f5abLL /* 251 */,
- 0xffed95d8f1ea02a2LL /* 252 */, 0xe72b3bd61464d43dLL /* 253 */,
- 0xa6300f170bdc4820LL /* 254 */, 0xebc18760ed78a77aLL /* 255 */
+ U64_C(0x02aab17cf7e90c5e) /* 0 */, U64_C(0xac424b03e243a8ec) /* 1 */,
+ U64_C(0x72cd5be30dd5fcd3) /* 2 */, U64_C(0x6d019b93f6f97f3a) /* 3 */,
+ U64_C(0xcd9978ffd21f9193) /* 4 */, U64_C(0x7573a1c9708029e2) /* 5 */,
+ U64_C(0xb164326b922a83c3) /* 6 */, U64_C(0x46883eee04915870) /* 7 */,
+ U64_C(0xeaace3057103ece6) /* 8 */, U64_C(0xc54169b808a3535c) /* 9 */,
+ U64_C(0x4ce754918ddec47c) /* 10 */, U64_C(0x0aa2f4dfdc0df40c) /* 11 */,
+ U64_C(0x10b76f18a74dbefa) /* 12 */, U64_C(0xc6ccb6235ad1ab6a) /* 13 */,
+ U64_C(0x13726121572fe2ff) /* 14 */, U64_C(0x1a488c6f199d921e) /* 15 */,
+ U64_C(0x4bc9f9f4da0007ca) /* 16 */, U64_C(0x26f5e6f6e85241c7) /* 17 */,
+ U64_C(0x859079dbea5947b6) /* 18 */, U64_C(0x4f1885c5c99e8c92) /* 19 */,
+ U64_C(0xd78e761ea96f864b) /* 20 */, U64_C(0x8e36428c52b5c17d) /* 21 */,
+ U64_C(0x69cf6827373063c1) /* 22 */, U64_C(0xb607c93d9bb4c56e) /* 23 */,
+ U64_C(0x7d820e760e76b5ea) /* 24 */, U64_C(0x645c9cc6f07fdc42) /* 25 */,
+ U64_C(0xbf38a078243342e0) /* 26 */, U64_C(0x5f6b343c9d2e7d04) /* 27 */,
+ U64_C(0xf2c28aeb600b0ec6) /* 28 */, U64_C(0x6c0ed85f7254bcac) /* 29 */,
+ U64_C(0x71592281a4db4fe5) /* 30 */, U64_C(0x1967fa69ce0fed9f) /* 31 */,
+ U64_C(0xfd5293f8b96545db) /* 32 */, U64_C(0xc879e9d7f2a7600b) /* 33 */,
+ U64_C(0x860248920193194e) /* 34 */, U64_C(0xa4f9533b2d9cc0b3) /* 35 */,
+ U64_C(0x9053836c15957613) /* 36 */, U64_C(0xdb6dcf8afc357bf1) /* 37 */,
+ U64_C(0x18beea7a7a370f57) /* 38 */, U64_C(0x037117ca50b99066) /* 39 */,
+ U64_C(0x6ab30a9774424a35) /* 40 */, U64_C(0xf4e92f02e325249b) /* 41 */,
+ U64_C(0x7739db07061ccae1) /* 42 */, U64_C(0xd8f3b49ceca42a05) /* 43 */,
+ U64_C(0xbd56be3f51382f73) /* 44 */, U64_C(0x45faed5843b0bb28) /* 45 */,
+ U64_C(0x1c813d5c11bf1f83) /* 46 */, U64_C(0x8af0e4b6d75fa169) /* 47 */,
+ U64_C(0x33ee18a487ad9999) /* 48 */, U64_C(0x3c26e8eab1c94410) /* 49 */,
+ U64_C(0xb510102bc0a822f9) /* 50 */, U64_C(0x141eef310ce6123b) /* 51 */,
+ U64_C(0xfc65b90059ddb154) /* 52 */, U64_C(0xe0158640c5e0e607) /* 53 */,
+ U64_C(0x884e079826c3a3cf) /* 54 */, U64_C(0x930d0d9523c535fd) /* 55 */,
+ U64_C(0x35638d754e9a2b00) /* 56 */, U64_C(0x4085fccf40469dd5) /* 57 */,
+ U64_C(0xc4b17ad28be23a4c) /* 58 */, U64_C(0xcab2f0fc6a3e6a2e) /* 59 */,
+ U64_C(0x2860971a6b943fcd) /* 60 */, U64_C(0x3dde6ee212e30446) /* 61 */,
+ U64_C(0x6222f32ae01765ae) /* 62 */, U64_C(0x5d550bb5478308fe) /* 63 */,
+ U64_C(0xa9efa98da0eda22a) /* 64 */, U64_C(0xc351a71686c40da7) /* 65 */,
+ U64_C(0x1105586d9c867c84) /* 66 */, U64_C(0xdcffee85fda22853) /* 67 */,
+ U64_C(0xccfbd0262c5eef76) /* 68 */, U64_C(0xbaf294cb8990d201) /* 69 */,
+ U64_C(0xe69464f52afad975) /* 70 */, U64_C(0x94b013afdf133e14) /* 71 */,
+ U64_C(0x06a7d1a32823c958) /* 72 */, U64_C(0x6f95fe5130f61119) /* 73 */,
+ U64_C(0xd92ab34e462c06c0) /* 74 */, U64_C(0xed7bde33887c71d2) /* 75 */,
+ U64_C(0x79746d6e6518393e) /* 76 */, U64_C(0x5ba419385d713329) /* 77 */,
+ U64_C(0x7c1ba6b948a97564) /* 78 */, U64_C(0x31987c197bfdac67) /* 79 */,
+ U64_C(0xde6c23c44b053d02) /* 80 */, U64_C(0x581c49fed002d64d) /* 81 */,
+ U64_C(0xdd474d6338261571) /* 82 */, U64_C(0xaa4546c3e473d062) /* 83 */,
+ U64_C(0x928fce349455f860) /* 84 */, U64_C(0x48161bbacaab94d9) /* 85 */,
+ U64_C(0x63912430770e6f68) /* 86 */, U64_C(0x6ec8a5e602c6641c) /* 87 */,
+ U64_C(0x87282515337ddd2b) /* 88 */, U64_C(0x2cda6b42034b701b) /* 89 */,
+ U64_C(0xb03d37c181cb096d) /* 90 */, U64_C(0xe108438266c71c6f) /* 91 */,
+ U64_C(0x2b3180c7eb51b255) /* 92 */, U64_C(0xdf92b82f96c08bbc) /* 93 */,
+ U64_C(0x5c68c8c0a632f3ba) /* 94 */, U64_C(0x5504cc861c3d0556) /* 95 */,
+ U64_C(0xabbfa4e55fb26b8f) /* 96 */, U64_C(0x41848b0ab3baceb4) /* 97 */,
+ U64_C(0xb334a273aa445d32) /* 98 */, U64_C(0xbca696f0a85ad881) /* 99 */,
+ U64_C(0x24f6ec65b528d56c) /* 100 */, U64_C(0x0ce1512e90f4524a) /* 101 */,
+ U64_C(0x4e9dd79d5506d35a) /* 102 */, U64_C(0x258905fac6ce9779) /* 103 */,
+ U64_C(0x2019295b3e109b33) /* 104 */, U64_C(0xf8a9478b73a054cc) /* 105 */,
+ U64_C(0x2924f2f934417eb0) /* 106 */, U64_C(0x3993357d536d1bc4) /* 107 */,
+ U64_C(0x38a81ac21db6ff8b) /* 108 */, U64_C(0x47c4fbf17d6016bf) /* 109 */,
+ U64_C(0x1e0faadd7667e3f5) /* 110 */, U64_C(0x7abcff62938beb96) /* 111 */,
+ U64_C(0xa78dad948fc179c9) /* 112 */, U64_C(0x8f1f98b72911e50d) /* 113 */,
+ U64_C(0x61e48eae27121a91) /* 114 */, U64_C(0x4d62f7ad31859808) /* 115 */,
+ U64_C(0xeceba345ef5ceaeb) /* 116 */, U64_C(0xf5ceb25ebc9684ce) /* 117 */,
+ U64_C(0xf633e20cb7f76221) /* 118 */, U64_C(0xa32cdf06ab8293e4) /* 119 */,
+ U64_C(0x985a202ca5ee2ca4) /* 120 */, U64_C(0xcf0b8447cc8a8fb1) /* 121 */,
+ U64_C(0x9f765244979859a3) /* 122 */, U64_C(0xa8d516b1a1240017) /* 123 */,
+ U64_C(0x0bd7ba3ebb5dc726) /* 124 */, U64_C(0xe54bca55b86adb39) /* 125 */,
+ U64_C(0x1d7a3afd6c478063) /* 126 */, U64_C(0x519ec608e7669edd) /* 127 */,
+ U64_C(0x0e5715a2d149aa23) /* 128 */, U64_C(0x177d4571848ff194) /* 129 */,
+ U64_C(0xeeb55f3241014c22) /* 130 */, U64_C(0x0f5e5ca13a6e2ec2) /* 131 */,
+ U64_C(0x8029927b75f5c361) /* 132 */, U64_C(0xad139fabc3d6e436) /* 133 */,
+ U64_C(0x0d5df1a94ccf402f) /* 134 */, U64_C(0x3e8bd948bea5dfc8) /* 135 */,
+ U64_C(0xa5a0d357bd3ff77e) /* 136 */, U64_C(0xa2d12e251f74f645) /* 137 */,
+ U64_C(0x66fd9e525e81a082) /* 138 */, U64_C(0x2e0c90ce7f687a49) /* 139 */,
+ U64_C(0xc2e8bcbeba973bc5) /* 140 */, U64_C(0x000001bce509745f) /* 141 */,
+ U64_C(0x423777bbe6dab3d6) /* 142 */, U64_C(0xd1661c7eaef06eb5) /* 143 */,
+ U64_C(0xa1781f354daacfd8) /* 144 */, U64_C(0x2d11284a2b16affc) /* 145 */,
+ U64_C(0xf1fc4f67fa891d1f) /* 146 */, U64_C(0x73ecc25dcb920ada) /* 147 */,
+ U64_C(0xae610c22c2a12651) /* 148 */, U64_C(0x96e0a810d356b78a) /* 149 */,
+ U64_C(0x5a9a381f2fe7870f) /* 150 */, U64_C(0xd5ad62ede94e5530) /* 151 */,
+ U64_C(0xd225e5e8368d1427) /* 152 */, U64_C(0x65977b70c7af4631) /* 153 */,
+ U64_C(0x99f889b2de39d74f) /* 154 */, U64_C(0x233f30bf54e1d143) /* 155 */,
+ U64_C(0x9a9675d3d9a63c97) /* 156 */, U64_C(0x5470554ff334f9a8) /* 157 */,
+ U64_C(0x166acb744a4f5688) /* 158 */, U64_C(0x70c74caab2e4aead) /* 159 */,
+ U64_C(0xf0d091646f294d12) /* 160 */, U64_C(0x57b82a89684031d1) /* 161 */,
+ U64_C(0xefd95a5a61be0b6b) /* 162 */, U64_C(0x2fbd12e969f2f29a) /* 163 */,
+ U64_C(0x9bd37013feff9fe8) /* 164 */, U64_C(0x3f9b0404d6085a06) /* 165 */,
+ U64_C(0x4940c1f3166cfe15) /* 166 */, U64_C(0x09542c4dcdf3defb) /* 167 */,
+ U64_C(0xb4c5218385cd5ce3) /* 168 */, U64_C(0xc935b7dc4462a641) /* 169 */,
+ U64_C(0x3417f8a68ed3b63f) /* 170 */, U64_C(0xb80959295b215b40) /* 171 */,
+ U64_C(0xf99cdaef3b8c8572) /* 172 */, U64_C(0x018c0614f8fcb95d) /* 173 */,
+ U64_C(0x1b14accd1a3acdf3) /* 174 */, U64_C(0x84d471f200bb732d) /* 175 */,
+ U64_C(0xc1a3110e95e8da16) /* 176 */, U64_C(0x430a7220bf1a82b8) /* 177 */,
+ U64_C(0xb77e090d39df210e) /* 178 */, U64_C(0x5ef4bd9f3cd05e9d) /* 179 */,
+ U64_C(0x9d4ff6da7e57a444) /* 180 */, U64_C(0xda1d60e183d4a5f8) /* 181 */,
+ U64_C(0xb287c38417998e47) /* 182 */, U64_C(0xfe3edc121bb31886) /* 183 */,
+ U64_C(0xc7fe3ccc980ccbef) /* 184 */, U64_C(0xe46fb590189bfd03) /* 185 */,
+ U64_C(0x3732fd469a4c57dc) /* 186 */, U64_C(0x7ef700a07cf1ad65) /* 187 */,
+ U64_C(0x59c64468a31d8859) /* 188 */, U64_C(0x762fb0b4d45b61f6) /* 189 */,
+ U64_C(0x155baed099047718) /* 190 */, U64_C(0x68755e4c3d50baa6) /* 191 */,
+ U64_C(0xe9214e7f22d8b4df) /* 192 */, U64_C(0x2addbf532eac95f4) /* 193 */,
+ U64_C(0x32ae3909b4bd0109) /* 194 */, U64_C(0x834df537b08e3450) /* 195 */,
+ U64_C(0xfa209da84220728d) /* 196 */, U64_C(0x9e691d9b9efe23f7) /* 197 */,
+ U64_C(0x0446d288c4ae8d7f) /* 198 */, U64_C(0x7b4cc524e169785b) /* 199 */,
+ U64_C(0x21d87f0135ca1385) /* 200 */, U64_C(0xcebb400f137b8aa5) /* 201 */,
+ U64_C(0x272e2b66580796be) /* 202 */, U64_C(0x3612264125c2b0de) /* 203 */,
+ U64_C(0x057702bdad1efbb2) /* 204 */, U64_C(0xd4babb8eacf84be9) /* 205 */,
+ U64_C(0x91583139641bc67b) /* 206 */, U64_C(0x8bdc2de08036e024) /* 207 */,
+ U64_C(0x603c8156f49f68ed) /* 208 */, U64_C(0xf7d236f7dbef5111) /* 209 */,
+ U64_C(0x9727c4598ad21e80) /* 210 */, U64_C(0xa08a0896670a5fd7) /* 211 */,
+ U64_C(0xcb4a8f4309eba9cb) /* 212 */, U64_C(0x81af564b0f7036a1) /* 213 */,
+ U64_C(0xc0b99aa778199abd) /* 214 */, U64_C(0x959f1ec83fc8e952) /* 215 */,
+ U64_C(0x8c505077794a81b9) /* 216 */, U64_C(0x3acaaf8f056338f0) /* 217 */,
+ U64_C(0x07b43f50627a6778) /* 218 */, U64_C(0x4a44ab49f5eccc77) /* 219 */,
+ U64_C(0x3bc3d6e4b679ee98) /* 220 */, U64_C(0x9cc0d4d1cf14108c) /* 221 */,
+ U64_C(0x4406c00b206bc8a0) /* 222 */, U64_C(0x82a18854c8d72d89) /* 223 */,
+ U64_C(0x67e366b35c3c432c) /* 224 */, U64_C(0xb923dd61102b37f2) /* 225 */,
+ U64_C(0x56ab2779d884271d) /* 226 */, U64_C(0xbe83e1b0ff1525af) /* 227 */,
+ U64_C(0xfb7c65d4217e49a9) /* 228 */, U64_C(0x6bdbe0e76d48e7d4) /* 229 */,
+ U64_C(0x08df828745d9179e) /* 230 */, U64_C(0x22ea6a9add53bd34) /* 231 */,
+ U64_C(0xe36e141c5622200a) /* 232 */, U64_C(0x7f805d1b8cb750ee) /* 233 */,
+ U64_C(0xafe5c7a59f58e837) /* 234 */, U64_C(0xe27f996a4fb1c23c) /* 235 */,
+ U64_C(0xd3867dfb0775f0d0) /* 236 */, U64_C(0xd0e673de6e88891a) /* 237 */,
+ U64_C(0x123aeb9eafb86c25) /* 238 */, U64_C(0x30f1d5d5c145b895) /* 239 */,
+ U64_C(0xbb434a2dee7269e7) /* 240 */, U64_C(0x78cb67ecf931fa38) /* 241 */,
+ U64_C(0xf33b0372323bbf9c) /* 242 */, U64_C(0x52d66336fb279c74) /* 243 */,
+ U64_C(0x505f33ac0afb4eaa) /* 244 */, U64_C(0xe8a5cd99a2cce187) /* 245 */,
+ U64_C(0x534974801e2d30bb) /* 246 */, U64_C(0x8d2d5711d5876d90) /* 247 */,
+ U64_C(0x1f1a412891bc038e) /* 248 */, U64_C(0xd6e2e71d82e56648) /* 249 */,
+ U64_C(0x74036c3a497732b7) /* 250 */, U64_C(0x89b67ed96361f5ab) /* 251 */,
+ U64_C(0xffed95d8f1ea02a2) /* 252 */, U64_C(0xe72b3bd61464d43d) /* 253 */,
+ U64_C(0xa6300f170bdc4820) /* 254 */, U64_C(0xebc18760ed78a77a) /* 255 */
};
static u64 sbox2[256] = {
- 0xe6a6be5a05a12138LL /* 256 */, 0xb5a122a5b4f87c98LL /* 257 */,
- 0x563c6089140b6990LL /* 258 */, 0x4c46cb2e391f5dd5LL /* 259 */,
- 0xd932addbc9b79434LL /* 260 */, 0x08ea70e42015aff5LL /* 261 */,
- 0xd765a6673e478cf1LL /* 262 */, 0xc4fb757eab278d99LL /* 263 */,
- 0xdf11c6862d6e0692LL /* 264 */, 0xddeb84f10d7f3b16LL /* 265 */,
- 0x6f2ef604a665ea04LL /* 266 */, 0x4a8e0f0ff0e0dfb3LL /* 267 */,
- 0xa5edeef83dbcba51LL /* 268 */, 0xfc4f0a2a0ea4371eLL /* 269 */,
- 0xe83e1da85cb38429LL /* 270 */, 0xdc8ff882ba1b1ce2LL /* 271 */,
- 0xcd45505e8353e80dLL /* 272 */, 0x18d19a00d4db0717LL /* 273 */,
- 0x34a0cfeda5f38101LL /* 274 */, 0x0be77e518887caf2LL /* 275 */,
- 0x1e341438b3c45136LL /* 276 */, 0xe05797f49089ccf9LL /* 277 */,
- 0xffd23f9df2591d14LL /* 278 */, 0x543dda228595c5cdLL /* 279 */,
- 0x661f81fd99052a33LL /* 280 */, 0x8736e641db0f7b76LL /* 281 */,
- 0x15227725418e5307LL /* 282 */, 0xe25f7f46162eb2faLL /* 283 */,
- 0x48a8b2126c13d9feLL /* 284 */, 0xafdc541792e76eeaLL /* 285 */,
- 0x03d912bfc6d1898fLL /* 286 */, 0x31b1aafa1b83f51bLL /* 287 */,
- 0xf1ac2796e42ab7d9LL /* 288 */, 0x40a3a7d7fcd2ebacLL /* 289 */,
- 0x1056136d0afbbcc5LL /* 290 */, 0x7889e1dd9a6d0c85LL /* 291 */,
- 0xd33525782a7974aaLL /* 292 */, 0xa7e25d09078ac09bLL /* 293 */,
- 0xbd4138b3eac6edd0LL /* 294 */, 0x920abfbe71eb9e70LL /* 295 */,
- 0xa2a5d0f54fc2625cLL /* 296 */, 0xc054e36b0b1290a3LL /* 297 */,
- 0xf6dd59ff62fe932bLL /* 298 */, 0x3537354511a8ac7dLL /* 299 */,
- 0xca845e9172fadcd4LL /* 300 */, 0x84f82b60329d20dcLL /* 301 */,
- 0x79c62ce1cd672f18LL /* 302 */, 0x8b09a2add124642cLL /* 303 */,
- 0xd0c1e96a19d9e726LL /* 304 */, 0x5a786a9b4ba9500cLL /* 305 */,
- 0x0e020336634c43f3LL /* 306 */, 0xc17b474aeb66d822LL /* 307 */,
- 0x6a731ae3ec9baac2LL /* 308 */, 0x8226667ae0840258LL /* 309 */,
- 0x67d4567691caeca5LL /* 310 */, 0x1d94155c4875adb5LL /* 311 */,
- 0x6d00fd985b813fdfLL /* 312 */, 0x51286efcb774cd06LL /* 313 */,
- 0x5e8834471fa744afLL /* 314 */, 0xf72ca0aee761ae2eLL /* 315 */,
- 0xbe40e4cdaee8e09aLL /* 316 */, 0xe9970bbb5118f665LL /* 317 */,
- 0x726e4beb33df1964LL /* 318 */, 0x703b000729199762LL /* 319 */,
- 0x4631d816f5ef30a7LL /* 320 */, 0xb880b5b51504a6beLL /* 321 */,
- 0x641793c37ed84b6cLL /* 322 */, 0x7b21ed77f6e97d96LL /* 323 */,
- 0x776306312ef96b73LL /* 324 */, 0xae528948e86ff3f4LL /* 325 */,
- 0x53dbd7f286a3f8f8LL /* 326 */, 0x16cadce74cfc1063LL /* 327 */,
- 0x005c19bdfa52c6ddLL /* 328 */, 0x68868f5d64d46ad3LL /* 329 */,
- 0x3a9d512ccf1e186aLL /* 330 */, 0x367e62c2385660aeLL /* 331 */,
- 0xe359e7ea77dcb1d7LL /* 332 */, 0x526c0773749abe6eLL /* 333 */,
- 0x735ae5f9d09f734bLL /* 334 */, 0x493fc7cc8a558ba8LL /* 335 */,
- 0xb0b9c1533041ab45LL /* 336 */, 0x321958ba470a59bdLL /* 337 */,
- 0x852db00b5f46c393LL /* 338 */, 0x91209b2bd336b0e5LL /* 339 */,
- 0x6e604f7d659ef19fLL /* 340 */, 0xb99a8ae2782ccb24LL /* 341 */,
- 0xccf52ab6c814c4c7LL /* 342 */, 0x4727d9afbe11727bLL /* 343 */,
- 0x7e950d0c0121b34dLL /* 344 */, 0x756f435670ad471fLL /* 345 */,
- 0xf5add442615a6849LL /* 346 */, 0x4e87e09980b9957aLL /* 347 */,
- 0x2acfa1df50aee355LL /* 348 */, 0xd898263afd2fd556LL /* 349 */,
- 0xc8f4924dd80c8fd6LL /* 350 */, 0xcf99ca3d754a173aLL /* 351 */,
- 0xfe477bacaf91bf3cLL /* 352 */, 0xed5371f6d690c12dLL /* 353 */,
- 0x831a5c285e687094LL /* 354 */, 0xc5d3c90a3708a0a4LL /* 355 */,
- 0x0f7f903717d06580LL /* 356 */, 0x19f9bb13b8fdf27fLL /* 357 */,
- 0xb1bd6f1b4d502843LL /* 358 */, 0x1c761ba38fff4012LL /* 359 */,
- 0x0d1530c4e2e21f3bLL /* 360 */, 0x8943ce69a7372c8aLL /* 361 */,
- 0xe5184e11feb5ce66LL /* 362 */, 0x618bdb80bd736621LL /* 363 */,
- 0x7d29bad68b574d0bLL /* 364 */, 0x81bb613e25e6fe5bLL /* 365 */,
- 0x071c9c10bc07913fLL /* 366 */, 0xc7beeb7909ac2d97LL /* 367 */,
- 0xc3e58d353bc5d757LL /* 368 */, 0xeb017892f38f61e8LL /* 369 */,
- 0xd4effb9c9b1cc21aLL /* 370 */, 0x99727d26f494f7abLL /* 371 */,
- 0xa3e063a2956b3e03LL /* 372 */, 0x9d4a8b9a4aa09c30LL /* 373 */,
- 0x3f6ab7d500090fb4LL /* 374 */, 0x9cc0f2a057268ac0LL /* 375 */,
- 0x3dee9d2dedbf42d1LL /* 376 */, 0x330f49c87960a972LL /* 377 */,
- 0xc6b2720287421b41LL /* 378 */, 0x0ac59ec07c00369cLL /* 379 */,
- 0xef4eac49cb353425LL /* 380 */, 0xf450244eef0129d8LL /* 381 */,
- 0x8acc46e5caf4deb6LL /* 382 */, 0x2ffeab63989263f7LL /* 383 */,
- 0x8f7cb9fe5d7a4578LL /* 384 */, 0x5bd8f7644e634635LL /* 385 */,
- 0x427a7315bf2dc900LL /* 386 */, 0x17d0c4aa2125261cLL /* 387 */,
- 0x3992486c93518e50LL /* 388 */, 0xb4cbfee0a2d7d4c3LL /* 389 */,
- 0x7c75d6202c5ddd8dLL /* 390 */, 0xdbc295d8e35b6c61LL /* 391 */,
- 0x60b369d302032b19LL /* 392 */, 0xce42685fdce44132LL /* 393 */,
- 0x06f3ddb9ddf65610LL /* 394 */, 0x8ea4d21db5e148f0LL /* 395 */,
- 0x20b0fce62fcd496fLL /* 396 */, 0x2c1b912358b0ee31LL /* 397 */,
- 0xb28317b818f5a308LL /* 398 */, 0xa89c1e189ca6d2cfLL /* 399 */,
- 0x0c6b18576aaadbc8LL /* 400 */, 0xb65deaa91299fae3LL /* 401 */,
- 0xfb2b794b7f1027e7LL /* 402 */, 0x04e4317f443b5bebLL /* 403 */,
- 0x4b852d325939d0a6LL /* 404 */, 0xd5ae6beefb207ffcLL /* 405 */,
- 0x309682b281c7d374LL /* 406 */, 0xbae309a194c3b475LL /* 407 */,
- 0x8cc3f97b13b49f05LL /* 408 */, 0x98a9422ff8293967LL /* 409 */,
- 0x244b16b01076ff7cLL /* 410 */, 0xf8bf571c663d67eeLL /* 411 */,
- 0x1f0d6758eee30da1LL /* 412 */, 0xc9b611d97adeb9b7LL /* 413 */,
- 0xb7afd5887b6c57a2LL /* 414 */, 0x6290ae846b984fe1LL /* 415 */,
- 0x94df4cdeacc1a5fdLL /* 416 */, 0x058a5bd1c5483affLL /* 417 */,
- 0x63166cc142ba3c37LL /* 418 */, 0x8db8526eb2f76f40LL /* 419 */,
- 0xe10880036f0d6d4eLL /* 420 */, 0x9e0523c9971d311dLL /* 421 */,
- 0x45ec2824cc7cd691LL /* 422 */, 0x575b8359e62382c9LL /* 423 */,
- 0xfa9e400dc4889995LL /* 424 */, 0xd1823ecb45721568LL /* 425 */,
- 0xdafd983b8206082fLL /* 426 */, 0xaa7d29082386a8cbLL /* 427 */,
- 0x269fcd4403b87588LL /* 428 */, 0x1b91f5f728bdd1e0LL /* 429 */,
- 0xe4669f39040201f6LL /* 430 */, 0x7a1d7c218cf04adeLL /* 431 */,
- 0x65623c29d79ce5ceLL /* 432 */, 0x2368449096c00bb1LL /* 433 */,
- 0xab9bf1879da503baLL /* 434 */, 0xbc23ecb1a458058eLL /* 435 */,
- 0x9a58df01bb401eccLL /* 436 */, 0xa070e868a85f143dLL /* 437 */,
- 0x4ff188307df2239eLL /* 438 */, 0x14d565b41a641183LL /* 439 */,
- 0xee13337452701602LL /* 440 */, 0x950e3dcf3f285e09LL /* 441 */,
- 0x59930254b9c80953LL /* 442 */, 0x3bf299408930da6dLL /* 443 */,
- 0xa955943f53691387LL /* 444 */, 0xa15edecaa9cb8784LL /* 445 */,
- 0x29142127352be9a0LL /* 446 */, 0x76f0371fff4e7afbLL /* 447 */,
- 0x0239f450274f2228LL /* 448 */, 0xbb073af01d5e868bLL /* 449 */,
- 0xbfc80571c10e96c1LL /* 450 */, 0xd267088568222e23LL /* 451 */,
- 0x9671a3d48e80b5b0LL /* 452 */, 0x55b5d38ae193bb81LL /* 453 */,
- 0x693ae2d0a18b04b8LL /* 454 */, 0x5c48b4ecadd5335fLL /* 455 */,
- 0xfd743b194916a1caLL /* 456 */, 0x2577018134be98c4LL /* 457 */,
- 0xe77987e83c54a4adLL /* 458 */, 0x28e11014da33e1b9LL /* 459 */,
- 0x270cc59e226aa213LL /* 460 */, 0x71495f756d1a5f60LL /* 461 */,
- 0x9be853fb60afef77LL /* 462 */, 0xadc786a7f7443dbfLL /* 463 */,
- 0x0904456173b29a82LL /* 464 */, 0x58bc7a66c232bd5eLL /* 465 */,
- 0xf306558c673ac8b2LL /* 466 */, 0x41f639c6b6c9772aLL /* 467 */,
- 0x216defe99fda35daLL /* 468 */, 0x11640cc71c7be615LL /* 469 */,
- 0x93c43694565c5527LL /* 470 */, 0xea038e6246777839LL /* 471 */,
- 0xf9abf3ce5a3e2469LL /* 472 */, 0x741e768d0fd312d2LL /* 473 */,
- 0x0144b883ced652c6LL /* 474 */, 0xc20b5a5ba33f8552LL /* 475 */,
- 0x1ae69633c3435a9dLL /* 476 */, 0x97a28ca4088cfdecLL /* 477 */,
- 0x8824a43c1e96f420LL /* 478 */, 0x37612fa66eeea746LL /* 479 */,
- 0x6b4cb165f9cf0e5aLL /* 480 */, 0x43aa1c06a0abfb4aLL /* 481 */,
- 0x7f4dc26ff162796bLL /* 482 */, 0x6cbacc8e54ed9b0fLL /* 483 */,
- 0xa6b7ffefd2bb253eLL /* 484 */, 0x2e25bc95b0a29d4fLL /* 485 */,
- 0x86d6a58bdef1388cLL /* 486 */, 0xded74ac576b6f054LL /* 487 */,
- 0x8030bdbc2b45805dLL /* 488 */, 0x3c81af70e94d9289LL /* 489 */,
- 0x3eff6dda9e3100dbLL /* 490 */, 0xb38dc39fdfcc8847LL /* 491 */,
- 0x123885528d17b87eLL /* 492 */, 0xf2da0ed240b1b642LL /* 493 */,
- 0x44cefadcd54bf9a9LL /* 494 */, 0x1312200e433c7ee6LL /* 495 */,
- 0x9ffcc84f3a78c748LL /* 496 */, 0xf0cd1f72248576bbLL /* 497 */,
- 0xec6974053638cfe4LL /* 498 */, 0x2ba7b67c0cec4e4cLL /* 499 */,
- 0xac2f4df3e5ce32edLL /* 500 */, 0xcb33d14326ea4c11LL /* 501 */,
- 0xa4e9044cc77e58bcLL /* 502 */, 0x5f513293d934fcefLL /* 503 */,
- 0x5dc9645506e55444LL /* 504 */, 0x50de418f317de40aLL /* 505 */,
- 0x388cb31a69dde259LL /* 506 */, 0x2db4a83455820a86LL /* 507 */,
- 0x9010a91e84711ae9LL /* 508 */, 0x4df7f0b7b1498371LL /* 509 */,
- 0xd62a2eabc0977179LL /* 510 */, 0x22fac097aa8d5c0eLL /* 511 */
+ U64_C(0xe6a6be5a05a12138) /* 256 */, U64_C(0xb5a122a5b4f87c98) /* 257 */,
+ U64_C(0x563c6089140b6990) /* 258 */, U64_C(0x4c46cb2e391f5dd5) /* 259 */,
+ U64_C(0xd932addbc9b79434) /* 260 */, U64_C(0x08ea70e42015aff5) /* 261 */,
+ U64_C(0xd765a6673e478cf1) /* 262 */, U64_C(0xc4fb757eab278d99) /* 263 */,
+ U64_C(0xdf11c6862d6e0692) /* 264 */, U64_C(0xddeb84f10d7f3b16) /* 265 */,
+ U64_C(0x6f2ef604a665ea04) /* 266 */, U64_C(0x4a8e0f0ff0e0dfb3) /* 267 */,
+ U64_C(0xa5edeef83dbcba51) /* 268 */, U64_C(0xfc4f0a2a0ea4371e) /* 269 */,
+ U64_C(0xe83e1da85cb38429) /* 270 */, U64_C(0xdc8ff882ba1b1ce2) /* 271 */,
+ U64_C(0xcd45505e8353e80d) /* 272 */, U64_C(0x18d19a00d4db0717) /* 273 */,
+ U64_C(0x34a0cfeda5f38101) /* 274 */, U64_C(0x0be77e518887caf2) /* 275 */,
+ U64_C(0x1e341438b3c45136) /* 276 */, U64_C(0xe05797f49089ccf9) /* 277 */,
+ U64_C(0xffd23f9df2591d14) /* 278 */, U64_C(0x543dda228595c5cd) /* 279 */,
+ U64_C(0x661f81fd99052a33) /* 280 */, U64_C(0x8736e641db0f7b76) /* 281 */,
+ U64_C(0x15227725418e5307) /* 282 */, U64_C(0xe25f7f46162eb2fa) /* 283 */,
+ U64_C(0x48a8b2126c13d9fe) /* 284 */, U64_C(0xafdc541792e76eea) /* 285 */,
+ U64_C(0x03d912bfc6d1898f) /* 286 */, U64_C(0x31b1aafa1b83f51b) /* 287 */,
+ U64_C(0xf1ac2796e42ab7d9) /* 288 */, U64_C(0x40a3a7d7fcd2ebac) /* 289 */,
+ U64_C(0x1056136d0afbbcc5) /* 290 */, U64_C(0x7889e1dd9a6d0c85) /* 291 */,
+ U64_C(0xd33525782a7974aa) /* 292 */, U64_C(0xa7e25d09078ac09b) /* 293 */,
+ U64_C(0xbd4138b3eac6edd0) /* 294 */, U64_C(0x920abfbe71eb9e70) /* 295 */,
+ U64_C(0xa2a5d0f54fc2625c) /* 296 */, U64_C(0xc054e36b0b1290a3) /* 297 */,
+ U64_C(0xf6dd59ff62fe932b) /* 298 */, U64_C(0x3537354511a8ac7d) /* 299 */,
+ U64_C(0xca845e9172fadcd4) /* 300 */, U64_C(0x84f82b60329d20dc) /* 301 */,
+ U64_C(0x79c62ce1cd672f18) /* 302 */, U64_C(0x8b09a2add124642c) /* 303 */,
+ U64_C(0xd0c1e96a19d9e726) /* 304 */, U64_C(0x5a786a9b4ba9500c) /* 305 */,
+ U64_C(0x0e020336634c43f3) /* 306 */, U64_C(0xc17b474aeb66d822) /* 307 */,
+ U64_C(0x6a731ae3ec9baac2) /* 308 */, U64_C(0x8226667ae0840258) /* 309 */,
+ U64_C(0x67d4567691caeca5) /* 310 */, U64_C(0x1d94155c4875adb5) /* 311 */,
+ U64_C(0x6d00fd985b813fdf) /* 312 */, U64_C(0x51286efcb774cd06) /* 313 */,
+ U64_C(0x5e8834471fa744af) /* 314 */, U64_C(0xf72ca0aee761ae2e) /* 315 */,
+ U64_C(0xbe40e4cdaee8e09a) /* 316 */, U64_C(0xe9970bbb5118f665) /* 317 */,
+ U64_C(0x726e4beb33df1964) /* 318 */, U64_C(0x703b000729199762) /* 319 */,
+ U64_C(0x4631d816f5ef30a7) /* 320 */, U64_C(0xb880b5b51504a6be) /* 321 */,
+ U64_C(0x641793c37ed84b6c) /* 322 */, U64_C(0x7b21ed77f6e97d96) /* 323 */,
+ U64_C(0x776306312ef96b73) /* 324 */, U64_C(0xae528948e86ff3f4) /* 325 */,
+ U64_C(0x53dbd7f286a3f8f8) /* 326 */, U64_C(0x16cadce74cfc1063) /* 327 */,
+ U64_C(0x005c19bdfa52c6dd) /* 328 */, U64_C(0x68868f5d64d46ad3) /* 329 */,
+ U64_C(0x3a9d512ccf1e186a) /* 330 */, U64_C(0x367e62c2385660ae) /* 331 */,
+ U64_C(0xe359e7ea77dcb1d7) /* 332 */, U64_C(0x526c0773749abe6e) /* 333 */,
+ U64_C(0x735ae5f9d09f734b) /* 334 */, U64_C(0x493fc7cc8a558ba8) /* 335 */,
+ U64_C(0xb0b9c1533041ab45) /* 336 */, U64_C(0x321958ba470a59bd) /* 337 */,
+ U64_C(0x852db00b5f46c393) /* 338 */, U64_C(0x91209b2bd336b0e5) /* 339 */,
+ U64_C(0x6e604f7d659ef19f) /* 340 */, U64_C(0xb99a8ae2782ccb24) /* 341 */,
+ U64_C(0xccf52ab6c814c4c7) /* 342 */, U64_C(0x4727d9afbe11727b) /* 343 */,
+ U64_C(0x7e950d0c0121b34d) /* 344 */, U64_C(0x756f435670ad471f) /* 345 */,
+ U64_C(0xf5add442615a6849) /* 346 */, U64_C(0x4e87e09980b9957a) /* 347 */,
+ U64_C(0x2acfa1df50aee355) /* 348 */, U64_C(0xd898263afd2fd556) /* 349 */,
+ U64_C(0xc8f4924dd80c8fd6) /* 350 */, U64_C(0xcf99ca3d754a173a) /* 351 */,
+ U64_C(0xfe477bacaf91bf3c) /* 352 */, U64_C(0xed5371f6d690c12d) /* 353 */,
+ U64_C(0x831a5c285e687094) /* 354 */, U64_C(0xc5d3c90a3708a0a4) /* 355 */,
+ U64_C(0x0f7f903717d06580) /* 356 */, U64_C(0x19f9bb13b8fdf27f) /* 357 */,
+ U64_C(0xb1bd6f1b4d502843) /* 358 */, U64_C(0x1c761ba38fff4012) /* 359 */,
+ U64_C(0x0d1530c4e2e21f3b) /* 360 */, U64_C(0x8943ce69a7372c8a) /* 361 */,
+ U64_C(0xe5184e11feb5ce66) /* 362 */, U64_C(0x618bdb80bd736621) /* 363 */,
+ U64_C(0x7d29bad68b574d0b) /* 364 */, U64_C(0x81bb613e25e6fe5b) /* 365 */,
+ U64_C(0x071c9c10bc07913f) /* 366 */, U64_C(0xc7beeb7909ac2d97) /* 367 */,
+ U64_C(0xc3e58d353bc5d757) /* 368 */, U64_C(0xeb017892f38f61e8) /* 369 */,
+ U64_C(0xd4effb9c9b1cc21a) /* 370 */, U64_C(0x99727d26f494f7ab) /* 371 */,
+ U64_C(0xa3e063a2956b3e03) /* 372 */, U64_C(0x9d4a8b9a4aa09c30) /* 373 */,
+ U64_C(0x3f6ab7d500090fb4) /* 374 */, U64_C(0x9cc0f2a057268ac0) /* 375 */,
+ U64_C(0x3dee9d2dedbf42d1) /* 376 */, U64_C(0x330f49c87960a972) /* 377 */,
+ U64_C(0xc6b2720287421b41) /* 378 */, U64_C(0x0ac59ec07c00369c) /* 379 */,
+ U64_C(0xef4eac49cb353425) /* 380 */, U64_C(0xf450244eef0129d8) /* 381 */,
+ U64_C(0x8acc46e5caf4deb6) /* 382 */, U64_C(0x2ffeab63989263f7) /* 383 */,
+ U64_C(0x8f7cb9fe5d7a4578) /* 384 */, U64_C(0x5bd8f7644e634635) /* 385 */,
+ U64_C(0x427a7315bf2dc900) /* 386 */, U64_C(0x17d0c4aa2125261c) /* 387 */,
+ U64_C(0x3992486c93518e50) /* 388 */, U64_C(0xb4cbfee0a2d7d4c3) /* 389 */,
+ U64_C(0x7c75d6202c5ddd8d) /* 390 */, U64_C(0xdbc295d8e35b6c61) /* 391 */,
+ U64_C(0x60b369d302032b19) /* 392 */, U64_C(0xce42685fdce44132) /* 393 */,
+ U64_C(0x06f3ddb9ddf65610) /* 394 */, U64_C(0x8ea4d21db5e148f0) /* 395 */,
+ U64_C(0x20b0fce62fcd496f) /* 396 */, U64_C(0x2c1b912358b0ee31) /* 397 */,
+ U64_C(0xb28317b818f5a308) /* 398 */, U64_C(0xa89c1e189ca6d2cf) /* 399 */,
+ U64_C(0x0c6b18576aaadbc8) /* 400 */, U64_C(0xb65deaa91299fae3) /* 401 */,
+ U64_C(0xfb2b794b7f1027e7) /* 402 */, U64_C(0x04e4317f443b5beb) /* 403 */,
+ U64_C(0x4b852d325939d0a6) /* 404 */, U64_C(0xd5ae6beefb207ffc) /* 405 */,
+ U64_C(0x309682b281c7d374) /* 406 */, U64_C(0xbae309a194c3b475) /* 407 */,
+ U64_C(0x8cc3f97b13b49f05) /* 408 */, U64_C(0x98a9422ff8293967) /* 409 */,
+ U64_C(0x244b16b01076ff7c) /* 410 */, U64_C(0xf8bf571c663d67ee) /* 411 */,
+ U64_C(0x1f0d6758eee30da1) /* 412 */, U64_C(0xc9b611d97adeb9b7) /* 413 */,
+ U64_C(0xb7afd5887b6c57a2) /* 414 */, U64_C(0x6290ae846b984fe1) /* 415 */,
+ U64_C(0x94df4cdeacc1a5fd) /* 416 */, U64_C(0x058a5bd1c5483aff) /* 417 */,
+ U64_C(0x63166cc142ba3c37) /* 418 */, U64_C(0x8db8526eb2f76f40) /* 419 */,
+ U64_C(0xe10880036f0d6d4e) /* 420 */, U64_C(0x9e0523c9971d311d) /* 421 */,
+ U64_C(0x45ec2824cc7cd691) /* 422 */, U64_C(0x575b8359e62382c9) /* 423 */,
+ U64_C(0xfa9e400dc4889995) /* 424 */, U64_C(0xd1823ecb45721568) /* 425 */,
+ U64_C(0xdafd983b8206082f) /* 426 */, U64_C(0xaa7d29082386a8cb) /* 427 */,
+ U64_C(0x269fcd4403b87588) /* 428 */, U64_C(0x1b91f5f728bdd1e0) /* 429 */,
+ U64_C(0xe4669f39040201f6) /* 430 */, U64_C(0x7a1d7c218cf04ade) /* 431 */,
+ U64_C(0x65623c29d79ce5ce) /* 432 */, U64_C(0x2368449096c00bb1) /* 433 */,
+ U64_C(0xab9bf1879da503ba) /* 434 */, U64_C(0xbc23ecb1a458058e) /* 435 */,
+ U64_C(0x9a58df01bb401ecc) /* 436 */, U64_C(0xa070e868a85f143d) /* 437 */,
+ U64_C(0x4ff188307df2239e) /* 438 */, U64_C(0x14d565b41a641183) /* 439 */,
+ U64_C(0xee13337452701602) /* 440 */, U64_C(0x950e3dcf3f285e09) /* 441 */,
+ U64_C(0x59930254b9c80953) /* 442 */, U64_C(0x3bf299408930da6d) /* 443 */,
+ U64_C(0xa955943f53691387) /* 444 */, U64_C(0xa15edecaa9cb8784) /* 445 */,
+ U64_C(0x29142127352be9a0) /* 446 */, U64_C(0x76f0371fff4e7afb) /* 447 */,
+ U64_C(0x0239f450274f2228) /* 448 */, U64_C(0xbb073af01d5e868b) /* 449 */,
+ U64_C(0xbfc80571c10e96c1) /* 450 */, U64_C(0xd267088568222e23) /* 451 */,
+ U64_C(0x9671a3d48e80b5b0) /* 452 */, U64_C(0x55b5d38ae193bb81) /* 453 */,
+ U64_C(0x693ae2d0a18b04b8) /* 454 */, U64_C(0x5c48b4ecadd5335f) /* 455 */,
+ U64_C(0xfd743b194916a1ca) /* 456 */, U64_C(0x2577018134be98c4) /* 457 */,
+ U64_C(0xe77987e83c54a4ad) /* 458 */, U64_C(0x28e11014da33e1b9) /* 459 */,
+ U64_C(0x270cc59e226aa213) /* 460 */, U64_C(0x71495f756d1a5f60) /* 461 */,
+ U64_C(0x9be853fb60afef77) /* 462 */, U64_C(0xadc786a7f7443dbf) /* 463 */,
+ U64_C(0x0904456173b29a82) /* 464 */, U64_C(0x58bc7a66c232bd5e) /* 465 */,
+ U64_C(0xf306558c673ac8b2) /* 466 */, U64_C(0x41f639c6b6c9772a) /* 467 */,
+ U64_C(0x216defe99fda35da) /* 468 */, U64_C(0x11640cc71c7be615) /* 469 */,
+ U64_C(0x93c43694565c5527) /* 470 */, U64_C(0xea038e6246777839) /* 471 */,
+ U64_C(0xf9abf3ce5a3e2469) /* 472 */, U64_C(0x741e768d0fd312d2) /* 473 */,
+ U64_C(0x0144b883ced652c6) /* 474 */, U64_C(0xc20b5a5ba33f8552) /* 475 */,
+ U64_C(0x1ae69633c3435a9d) /* 476 */, U64_C(0x97a28ca4088cfdec) /* 477 */,
+ U64_C(0x8824a43c1e96f420) /* 478 */, U64_C(0x37612fa66eeea746) /* 479 */,
+ U64_C(0x6b4cb165f9cf0e5a) /* 480 */, U64_C(0x43aa1c06a0abfb4a) /* 481 */,
+ U64_C(0x7f4dc26ff162796b) /* 482 */, U64_C(0x6cbacc8e54ed9b0f) /* 483 */,
+ U64_C(0xa6b7ffefd2bb253e) /* 484 */, U64_C(0x2e25bc95b0a29d4f) /* 485 */,
+ U64_C(0x86d6a58bdef1388c) /* 486 */, U64_C(0xded74ac576b6f054) /* 487 */,
+ U64_C(0x8030bdbc2b45805d) /* 488 */, U64_C(0x3c81af70e94d9289) /* 489 */,
+ U64_C(0x3eff6dda9e3100db) /* 490 */, U64_C(0xb38dc39fdfcc8847) /* 491 */,
+ U64_C(0x123885528d17b87e) /* 492 */, U64_C(0xf2da0ed240b1b642) /* 493 */,
+ U64_C(0x44cefadcd54bf9a9) /* 494 */, U64_C(0x1312200e433c7ee6) /* 495 */,
+ U64_C(0x9ffcc84f3a78c748) /* 496 */, U64_C(0xf0cd1f72248576bb) /* 497 */,
+ U64_C(0xec6974053638cfe4) /* 498 */, U64_C(0x2ba7b67c0cec4e4c) /* 499 */,
+ U64_C(0xac2f4df3e5ce32ed) /* 500 */, U64_C(0xcb33d14326ea4c11) /* 501 */,
+ U64_C(0xa4e9044cc77e58bc) /* 502 */, U64_C(0x5f513293d934fcef) /* 503 */,
+ U64_C(0x5dc9645506e55444) /* 504 */, U64_C(0x50de418f317de40a) /* 505 */,
+ U64_C(0x388cb31a69dde259) /* 506 */, U64_C(0x2db4a83455820a86) /* 507 */,
+ U64_C(0x9010a91e84711ae9) /* 508 */, U64_C(0x4df7f0b7b1498371) /* 509 */,
+ U64_C(0xd62a2eabc0977179) /* 510 */, U64_C(0x22fac097aa8d5c0e) /* 511 */
};
static u64 sbox3[256] = {
- 0xf49fcc2ff1daf39bLL /* 512 */, 0x487fd5c66ff29281LL /* 513 */,
- 0xe8a30667fcdca83fLL /* 514 */, 0x2c9b4be3d2fcce63LL /* 515 */,
- 0xda3ff74b93fbbbc2LL /* 516 */, 0x2fa165d2fe70ba66LL /* 517 */,
- 0xa103e279970e93d4LL /* 518 */, 0xbecdec77b0e45e71LL /* 519 */,
- 0xcfb41e723985e497LL /* 520 */, 0xb70aaa025ef75017LL /* 521 */,
- 0xd42309f03840b8e0LL /* 522 */, 0x8efc1ad035898579LL /* 523 */,
- 0x96c6920be2b2abc5LL /* 524 */, 0x66af4163375a9172LL /* 525 */,
- 0x2174abdcca7127fbLL /* 526 */, 0xb33ccea64a72ff41LL /* 527 */,
- 0xf04a4933083066a5LL /* 528 */, 0x8d970acdd7289af5LL /* 529 */,
- 0x8f96e8e031c8c25eLL /* 530 */, 0xf3fec02276875d47LL /* 531 */,
- 0xec7bf310056190ddLL /* 532 */, 0xf5adb0aebb0f1491LL /* 533 */,
- 0x9b50f8850fd58892LL /* 534 */, 0x4975488358b74de8LL /* 535 */,
- 0xa3354ff691531c61LL /* 536 */, 0x0702bbe481d2c6eeLL /* 537 */,
- 0x89fb24057deded98LL /* 538 */, 0xac3075138596e902LL /* 539 */,
- 0x1d2d3580172772edLL /* 540 */, 0xeb738fc28e6bc30dLL /* 541 */,
- 0x5854ef8f63044326LL /* 542 */, 0x9e5c52325add3bbeLL /* 543 */,
- 0x90aa53cf325c4623LL /* 544 */, 0xc1d24d51349dd067LL /* 545 */,
- 0x2051cfeea69ea624LL /* 546 */, 0x13220f0a862e7e4fLL /* 547 */,
- 0xce39399404e04864LL /* 548 */, 0xd9c42ca47086fcb7LL /* 549 */,
- 0x685ad2238a03e7ccLL /* 550 */, 0x066484b2ab2ff1dbLL /* 551 */,
- 0xfe9d5d70efbf79ecLL /* 552 */, 0x5b13b9dd9c481854LL /* 553 */,
- 0x15f0d475ed1509adLL /* 554 */, 0x0bebcd060ec79851LL /* 555 */,
- 0xd58c6791183ab7f8LL /* 556 */, 0xd1187c5052f3eee4LL /* 557 */,
- 0xc95d1192e54e82ffLL /* 558 */, 0x86eea14cb9ac6ca2LL /* 559 */,
- 0x3485beb153677d5dLL /* 560 */, 0xdd191d781f8c492aLL /* 561 */,
- 0xf60866baa784ebf9LL /* 562 */, 0x518f643ba2d08c74LL /* 563 */,
- 0x8852e956e1087c22LL /* 564 */, 0xa768cb8dc410ae8dLL /* 565 */,
- 0x38047726bfec8e1aLL /* 566 */, 0xa67738b4cd3b45aaLL /* 567 */,
- 0xad16691cec0dde19LL /* 568 */, 0xc6d4319380462e07LL /* 569 */,
- 0xc5a5876d0ba61938LL /* 570 */, 0x16b9fa1fa58fd840LL /* 571 */,
- 0x188ab1173ca74f18LL /* 572 */, 0xabda2f98c99c021fLL /* 573 */,
- 0x3e0580ab134ae816LL /* 574 */, 0x5f3b05b773645abbLL /* 575 */,
- 0x2501a2be5575f2f6LL /* 576 */, 0x1b2f74004e7e8ba9LL /* 577 */,
- 0x1cd7580371e8d953LL /* 578 */, 0x7f6ed89562764e30LL /* 579 */,
- 0xb15926ff596f003dLL /* 580 */, 0x9f65293da8c5d6b9LL /* 581 */,
- 0x6ecef04dd690f84cLL /* 582 */, 0x4782275fff33af88LL /* 583 */,
- 0xe41433083f820801LL /* 584 */, 0xfd0dfe409a1af9b5LL /* 585 */,
- 0x4325a3342cdb396bLL /* 586 */, 0x8ae77e62b301b252LL /* 587 */,
- 0xc36f9e9f6655615aLL /* 588 */, 0x85455a2d92d32c09LL /* 589 */,
- 0xf2c7dea949477485LL /* 590 */, 0x63cfb4c133a39ebaLL /* 591 */,
- 0x83b040cc6ebc5462LL /* 592 */, 0x3b9454c8fdb326b0LL /* 593 */,
- 0x56f56a9e87ffd78cLL /* 594 */, 0x2dc2940d99f42bc6LL /* 595 */,
- 0x98f7df096b096e2dLL /* 596 */, 0x19a6e01e3ad852bfLL /* 597 */,
- 0x42a99ccbdbd4b40bLL /* 598 */, 0xa59998af45e9c559LL /* 599 */,
- 0x366295e807d93186LL /* 600 */, 0x6b48181bfaa1f773LL /* 601 */,
- 0x1fec57e2157a0a1dLL /* 602 */, 0x4667446af6201ad5LL /* 603 */,
- 0xe615ebcacfb0f075LL /* 604 */, 0xb8f31f4f68290778LL /* 605 */,
- 0x22713ed6ce22d11eLL /* 606 */, 0x3057c1a72ec3c93bLL /* 607 */,
- 0xcb46acc37c3f1f2fLL /* 608 */, 0xdbb893fd02aaf50eLL /* 609 */,
- 0x331fd92e600b9fcfLL /* 610 */, 0xa498f96148ea3ad6LL /* 611 */,
- 0xa8d8426e8b6a83eaLL /* 612 */, 0xa089b274b7735cdcLL /* 613 */,
- 0x87f6b3731e524a11LL /* 614 */, 0x118808e5cbc96749LL /* 615 */,
- 0x9906e4c7b19bd394LL /* 616 */, 0xafed7f7e9b24a20cLL /* 617 */,
- 0x6509eadeeb3644a7LL /* 618 */, 0x6c1ef1d3e8ef0edeLL /* 619 */,
- 0xb9c97d43e9798fb4LL /* 620 */, 0xa2f2d784740c28a3LL /* 621 */,
- 0x7b8496476197566fLL /* 622 */, 0x7a5be3e6b65f069dLL /* 623 */,
- 0xf96330ed78be6f10LL /* 624 */, 0xeee60de77a076a15LL /* 625 */,
- 0x2b4bee4aa08b9bd0LL /* 626 */, 0x6a56a63ec7b8894eLL /* 627 */,
- 0x02121359ba34fef4LL /* 628 */, 0x4cbf99f8283703fcLL /* 629 */,
- 0x398071350caf30c8LL /* 630 */, 0xd0a77a89f017687aLL /* 631 */,
- 0xf1c1a9eb9e423569LL /* 632 */, 0x8c7976282dee8199LL /* 633 */,
- 0x5d1737a5dd1f7abdLL /* 634 */, 0x4f53433c09a9fa80LL /* 635 */,
- 0xfa8b0c53df7ca1d9LL /* 636 */, 0x3fd9dcbc886ccb77LL /* 637 */,
- 0xc040917ca91b4720LL /* 638 */, 0x7dd00142f9d1dcdfLL /* 639 */,
- 0x8476fc1d4f387b58LL /* 640 */, 0x23f8e7c5f3316503LL /* 641 */,
- 0x032a2244e7e37339LL /* 642 */, 0x5c87a5d750f5a74bLL /* 643 */,
- 0x082b4cc43698992eLL /* 644 */, 0xdf917becb858f63cLL /* 645 */,
- 0x3270b8fc5bf86ddaLL /* 646 */, 0x10ae72bb29b5dd76LL /* 647 */,
- 0x576ac94e7700362bLL /* 648 */, 0x1ad112dac61efb8fLL /* 649 */,
- 0x691bc30ec5faa427LL /* 650 */, 0xff246311cc327143LL /* 651 */,
- 0x3142368e30e53206LL /* 652 */, 0x71380e31e02ca396LL /* 653 */,
- 0x958d5c960aad76f1LL /* 654 */, 0xf8d6f430c16da536LL /* 655 */,
- 0xc8ffd13f1be7e1d2LL /* 656 */, 0x7578ae66004ddbe1LL /* 657 */,
- 0x05833f01067be646LL /* 658 */, 0xbb34b5ad3bfe586dLL /* 659 */,
- 0x095f34c9a12b97f0LL /* 660 */, 0x247ab64525d60ca8LL /* 661 */,
- 0xdcdbc6f3017477d1LL /* 662 */, 0x4a2e14d4decad24dLL /* 663 */,
- 0xbdb5e6d9be0a1eebLL /* 664 */, 0x2a7e70f7794301abLL /* 665 */,
- 0xdef42d8a270540fdLL /* 666 */, 0x01078ec0a34c22c1LL /* 667 */,
- 0xe5de511af4c16387LL /* 668 */, 0x7ebb3a52bd9a330aLL /* 669 */,
- 0x77697857aa7d6435LL /* 670 */, 0x004e831603ae4c32LL /* 671 */,
- 0xe7a21020ad78e312LL /* 672 */, 0x9d41a70c6ab420f2LL /* 673 */,
- 0x28e06c18ea1141e6LL /* 674 */, 0xd2b28cbd984f6b28LL /* 675 */,
- 0x26b75f6c446e9d83LL /* 676 */, 0xba47568c4d418d7fLL /* 677 */,
- 0xd80badbfe6183d8eLL /* 678 */, 0x0e206d7f5f166044LL /* 679 */,
- 0xe258a43911cbca3eLL /* 680 */, 0x723a1746b21dc0bcLL /* 681 */,
- 0xc7caa854f5d7cdd3LL /* 682 */, 0x7cac32883d261d9cLL /* 683 */,
- 0x7690c26423ba942cLL /* 684 */, 0x17e55524478042b8LL /* 685 */,
- 0xe0be477656a2389fLL /* 686 */, 0x4d289b5e67ab2da0LL /* 687 */,
- 0x44862b9c8fbbfd31LL /* 688 */, 0xb47cc8049d141365LL /* 689 */,
- 0x822c1b362b91c793LL /* 690 */, 0x4eb14655fb13dfd8LL /* 691 */,
- 0x1ecbba0714e2a97bLL /* 692 */, 0x6143459d5cde5f14LL /* 693 */,
- 0x53a8fbf1d5f0ac89LL /* 694 */, 0x97ea04d81c5e5b00LL /* 695 */,
- 0x622181a8d4fdb3f3LL /* 696 */, 0xe9bcd341572a1208LL /* 697 */,
- 0x1411258643cce58aLL /* 698 */, 0x9144c5fea4c6e0a4LL /* 699 */,
- 0x0d33d06565cf620fLL /* 700 */, 0x54a48d489f219ca1LL /* 701 */,
- 0xc43e5eac6d63c821LL /* 702 */, 0xa9728b3a72770dafLL /* 703 */,
- 0xd7934e7b20df87efLL /* 704 */, 0xe35503b61a3e86e5LL /* 705 */,
- 0xcae321fbc819d504LL /* 706 */, 0x129a50b3ac60bfa6LL /* 707 */,
- 0xcd5e68ea7e9fb6c3LL /* 708 */, 0xb01c90199483b1c7LL /* 709 */,
- 0x3de93cd5c295376cLL /* 710 */, 0xaed52edf2ab9ad13LL /* 711 */,
- 0x2e60f512c0a07884LL /* 712 */, 0xbc3d86a3e36210c9LL /* 713 */,
- 0x35269d9b163951ceLL /* 714 */, 0x0c7d6e2ad0cdb5faLL /* 715 */,
- 0x59e86297d87f5733LL /* 716 */, 0x298ef221898db0e7LL /* 717 */,
- 0x55000029d1a5aa7eLL /* 718 */, 0x8bc08ae1b5061b45LL /* 719 */,
- 0xc2c31c2b6c92703aLL /* 720 */, 0x94cc596baf25ef42LL /* 721 */,
- 0x0a1d73db22540456LL /* 722 */, 0x04b6a0f9d9c4179aLL /* 723 */,
- 0xeffdafa2ae3d3c60LL /* 724 */, 0xf7c8075bb49496c4LL /* 725 */,
- 0x9cc5c7141d1cd4e3LL /* 726 */, 0x78bd1638218e5534LL /* 727 */,
- 0xb2f11568f850246aLL /* 728 */, 0xedfabcfa9502bc29LL /* 729 */,
- 0x796ce5f2da23051bLL /* 730 */, 0xaae128b0dc93537cLL /* 731 */,
- 0x3a493da0ee4b29aeLL /* 732 */, 0xb5df6b2c416895d7LL /* 733 */,
- 0xfcabbd25122d7f37LL /* 734 */, 0x70810b58105dc4b1LL /* 735 */,
- 0xe10fdd37f7882a90LL /* 736 */, 0x524dcab5518a3f5cLL /* 737 */,
- 0x3c9e85878451255bLL /* 738 */, 0x4029828119bd34e2LL /* 739 */,
- 0x74a05b6f5d3ceccbLL /* 740 */, 0xb610021542e13ecaLL /* 741 */,
- 0x0ff979d12f59e2acLL /* 742 */, 0x6037da27e4f9cc50LL /* 743 */,
- 0x5e92975a0df1847dLL /* 744 */, 0xd66de190d3e623feLL /* 745 */,
- 0x5032d6b87b568048LL /* 746 */, 0x9a36b7ce8235216eLL /* 747 */,
- 0x80272a7a24f64b4aLL /* 748 */, 0x93efed8b8c6916f7LL /* 749 */,
- 0x37ddbff44cce1555LL /* 750 */, 0x4b95db5d4b99bd25LL /* 751 */,
- 0x92d3fda169812fc0LL /* 752 */, 0xfb1a4a9a90660bb6LL /* 753 */,
- 0x730c196946a4b9b2LL /* 754 */, 0x81e289aa7f49da68LL /* 755 */,
- 0x64669a0f83b1a05fLL /* 756 */, 0x27b3ff7d9644f48bLL /* 757 */,
- 0xcc6b615c8db675b3LL /* 758 */, 0x674f20b9bcebbe95LL /* 759 */,
- 0x6f31238275655982LL /* 760 */, 0x5ae488713e45cf05LL /* 761 */,
- 0xbf619f9954c21157LL /* 762 */, 0xeabac46040a8eae9LL /* 763 */,
- 0x454c6fe9f2c0c1cdLL /* 764 */, 0x419cf6496412691cLL /* 765 */,
- 0xd3dc3bef265b0f70LL /* 766 */, 0x6d0e60f5c3578a9eLL /* 767 */
+ U64_C(0xf49fcc2ff1daf39b) /* 512 */, U64_C(0x487fd5c66ff29281) /* 513 */,
+ U64_C(0xe8a30667fcdca83f) /* 514 */, U64_C(0x2c9b4be3d2fcce63) /* 515 */,
+ U64_C(0xda3ff74b93fbbbc2) /* 516 */, U64_C(0x2fa165d2fe70ba66) /* 517 */,
+ U64_C(0xa103e279970e93d4) /* 518 */, U64_C(0xbecdec77b0e45e71) /* 519 */,
+ U64_C(0xcfb41e723985e497) /* 520 */, U64_C(0xb70aaa025ef75017) /* 521 */,
+ U64_C(0xd42309f03840b8e0) /* 522 */, U64_C(0x8efc1ad035898579) /* 523 */,
+ U64_C(0x96c6920be2b2abc5) /* 524 */, U64_C(0x66af4163375a9172) /* 525 */,
+ U64_C(0x2174abdcca7127fb) /* 526 */, U64_C(0xb33ccea64a72ff41) /* 527 */,
+ U64_C(0xf04a4933083066a5) /* 528 */, U64_C(0x8d970acdd7289af5) /* 529 */,
+ U64_C(0x8f96e8e031c8c25e) /* 530 */, U64_C(0xf3fec02276875d47) /* 531 */,
+ U64_C(0xec7bf310056190dd) /* 532 */, U64_C(0xf5adb0aebb0f1491) /* 533 */,
+ U64_C(0x9b50f8850fd58892) /* 534 */, U64_C(0x4975488358b74de8) /* 535 */,
+ U64_C(0xa3354ff691531c61) /* 536 */, U64_C(0x0702bbe481d2c6ee) /* 537 */,
+ U64_C(0x89fb24057deded98) /* 538 */, U64_C(0xac3075138596e902) /* 539 */,
+ U64_C(0x1d2d3580172772ed) /* 540 */, U64_C(0xeb738fc28e6bc30d) /* 541 */,
+ U64_C(0x5854ef8f63044326) /* 542 */, U64_C(0x9e5c52325add3bbe) /* 543 */,
+ U64_C(0x90aa53cf325c4623) /* 544 */, U64_C(0xc1d24d51349dd067) /* 545 */,
+ U64_C(0x2051cfeea69ea624) /* 546 */, U64_C(0x13220f0a862e7e4f) /* 547 */,
+ U64_C(0xce39399404e04864) /* 548 */, U64_C(0xd9c42ca47086fcb7) /* 549 */,
+ U64_C(0x685ad2238a03e7cc) /* 550 */, U64_C(0x066484b2ab2ff1db) /* 551 */,
+ U64_C(0xfe9d5d70efbf79ec) /* 552 */, U64_C(0x5b13b9dd9c481854) /* 553 */,
+ U64_C(0x15f0d475ed1509ad) /* 554 */, U64_C(0x0bebcd060ec79851) /* 555 */,
+ U64_C(0xd58c6791183ab7f8) /* 556 */, U64_C(0xd1187c5052f3eee4) /* 557 */,
+ U64_C(0xc95d1192e54e82ff) /* 558 */, U64_C(0x86eea14cb9ac6ca2) /* 559 */,
+ U64_C(0x3485beb153677d5d) /* 560 */, U64_C(0xdd191d781f8c492a) /* 561 */,
+ U64_C(0xf60866baa784ebf9) /* 562 */, U64_C(0x518f643ba2d08c74) /* 563 */,
+ U64_C(0x8852e956e1087c22) /* 564 */, U64_C(0xa768cb8dc410ae8d) /* 565 */,
+ U64_C(0x38047726bfec8e1a) /* 566 */, U64_C(0xa67738b4cd3b45aa) /* 567 */,
+ U64_C(0xad16691cec0dde19) /* 568 */, U64_C(0xc6d4319380462e07) /* 569 */,
+ U64_C(0xc5a5876d0ba61938) /* 570 */, U64_C(0x16b9fa1fa58fd840) /* 571 */,
+ U64_C(0x188ab1173ca74f18) /* 572 */, U64_C(0xabda2f98c99c021f) /* 573 */,
+ U64_C(0x3e0580ab134ae816) /* 574 */, U64_C(0x5f3b05b773645abb) /* 575 */,
+ U64_C(0x2501a2be5575f2f6) /* 576 */, U64_C(0x1b2f74004e7e8ba9) /* 577 */,
+ U64_C(0x1cd7580371e8d953) /* 578 */, U64_C(0x7f6ed89562764e30) /* 579 */,
+ U64_C(0xb15926ff596f003d) /* 580 */, U64_C(0x9f65293da8c5d6b9) /* 581 */,
+ U64_C(0x6ecef04dd690f84c) /* 582 */, U64_C(0x4782275fff33af88) /* 583 */,
+ U64_C(0xe41433083f820801) /* 584 */, U64_C(0xfd0dfe409a1af9b5) /* 585 */,
+ U64_C(0x4325a3342cdb396b) /* 586 */, U64_C(0x8ae77e62b301b252) /* 587 */,
+ U64_C(0xc36f9e9f6655615a) /* 588 */, U64_C(0x85455a2d92d32c09) /* 589 */,
+ U64_C(0xf2c7dea949477485) /* 590 */, U64_C(0x63cfb4c133a39eba) /* 591 */,
+ U64_C(0x83b040cc6ebc5462) /* 592 */, U64_C(0x3b9454c8fdb326b0) /* 593 */,
+ U64_C(0x56f56a9e87ffd78c) /* 594 */, U64_C(0x2dc2940d99f42bc6) /* 595 */,
+ U64_C(0x98f7df096b096e2d) /* 596 */, U64_C(0x19a6e01e3ad852bf) /* 597 */,
+ U64_C(0x42a99ccbdbd4b40b) /* 598 */, U64_C(0xa59998af45e9c559) /* 599 */,
+ U64_C(0x366295e807d93186) /* 600 */, U64_C(0x6b48181bfaa1f773) /* 601 */,
+ U64_C(0x1fec57e2157a0a1d) /* 602 */, U64_C(0x4667446af6201ad5) /* 603 */,
+ U64_C(0xe615ebcacfb0f075) /* 604 */, U64_C(0xb8f31f4f68290778) /* 605 */,
+ U64_C(0x22713ed6ce22d11e) /* 606 */, U64_C(0x3057c1a72ec3c93b) /* 607 */,
+ U64_C(0xcb46acc37c3f1f2f) /* 608 */, U64_C(0xdbb893fd02aaf50e) /* 609 */,
+ U64_C(0x331fd92e600b9fcf) /* 610 */, U64_C(0xa498f96148ea3ad6) /* 611 */,
+ U64_C(0xa8d8426e8b6a83ea) /* 612 */, U64_C(0xa089b274b7735cdc) /* 613 */,
+ U64_C(0x87f6b3731e524a11) /* 614 */, U64_C(0x118808e5cbc96749) /* 615 */,
+ U64_C(0x9906e4c7b19bd394) /* 616 */, U64_C(0xafed7f7e9b24a20c) /* 617 */,
+ U64_C(0x6509eadeeb3644a7) /* 618 */, U64_C(0x6c1ef1d3e8ef0ede) /* 619 */,
+ U64_C(0xb9c97d43e9798fb4) /* 620 */, U64_C(0xa2f2d784740c28a3) /* 621 */,
+ U64_C(0x7b8496476197566f) /* 622 */, U64_C(0x7a5be3e6b65f069d) /* 623 */,
+ U64_C(0xf96330ed78be6f10) /* 624 */, U64_C(0xeee60de77a076a15) /* 625 */,
+ U64_C(0x2b4bee4aa08b9bd0) /* 626 */, U64_C(0x6a56a63ec7b8894e) /* 627 */,
+ U64_C(0x02121359ba34fef4) /* 628 */, U64_C(0x4cbf99f8283703fc) /* 629 */,
+ U64_C(0x398071350caf30c8) /* 630 */, U64_C(0xd0a77a89f017687a) /* 631 */,
+ U64_C(0xf1c1a9eb9e423569) /* 632 */, U64_C(0x8c7976282dee8199) /* 633 */,
+ U64_C(0x5d1737a5dd1f7abd) /* 634 */, U64_C(0x4f53433c09a9fa80) /* 635 */,
+ U64_C(0xfa8b0c53df7ca1d9) /* 636 */, U64_C(0x3fd9dcbc886ccb77) /* 637 */,
+ U64_C(0xc040917ca91b4720) /* 638 */, U64_C(0x7dd00142f9d1dcdf) /* 639 */,
+ U64_C(0x8476fc1d4f387b58) /* 640 */, U64_C(0x23f8e7c5f3316503) /* 641 */,
+ U64_C(0x032a2244e7e37339) /* 642 */, U64_C(0x5c87a5d750f5a74b) /* 643 */,
+ U64_C(0x082b4cc43698992e) /* 644 */, U64_C(0xdf917becb858f63c) /* 645 */,
+ U64_C(0x3270b8fc5bf86dda) /* 646 */, U64_C(0x10ae72bb29b5dd76) /* 647 */,
+ U64_C(0x576ac94e7700362b) /* 648 */, U64_C(0x1ad112dac61efb8f) /* 649 */,
+ U64_C(0x691bc30ec5faa427) /* 650 */, U64_C(0xff246311cc327143) /* 651 */,
+ U64_C(0x3142368e30e53206) /* 652 */, U64_C(0x71380e31e02ca396) /* 653 */,
+ U64_C(0x958d5c960aad76f1) /* 654 */, U64_C(0xf8d6f430c16da536) /* 655 */,
+ U64_C(0xc8ffd13f1be7e1d2) /* 656 */, U64_C(0x7578ae66004ddbe1) /* 657 */,
+ U64_C(0x05833f01067be646) /* 658 */, U64_C(0xbb34b5ad3bfe586d) /* 659 */,
+ U64_C(0x095f34c9a12b97f0) /* 660 */, U64_C(0x247ab64525d60ca8) /* 661 */,
+ U64_C(0xdcdbc6f3017477d1) /* 662 */, U64_C(0x4a2e14d4decad24d) /* 663 */,
+ U64_C(0xbdb5e6d9be0a1eeb) /* 664 */, U64_C(0x2a7e70f7794301ab) /* 665 */,
+ U64_C(0xdef42d8a270540fd) /* 666 */, U64_C(0x01078ec0a34c22c1) /* 667 */,
+ U64_C(0xe5de511af4c16387) /* 668 */, U64_C(0x7ebb3a52bd9a330a) /* 669 */,
+ U64_C(0x77697857aa7d6435) /* 670 */, U64_C(0x004e831603ae4c32) /* 671 */,
+ U64_C(0xe7a21020ad78e312) /* 672 */, U64_C(0x9d41a70c6ab420f2) /* 673 */,
+ U64_C(0x28e06c18ea1141e6) /* 674 */, U64_C(0xd2b28cbd984f6b28) /* 675 */,
+ U64_C(0x26b75f6c446e9d83) /* 676 */, U64_C(0xba47568c4d418d7f) /* 677 */,
+ U64_C(0xd80badbfe6183d8e) /* 678 */, U64_C(0x0e206d7f5f166044) /* 679 */,
+ U64_C(0xe258a43911cbca3e) /* 680 */, U64_C(0x723a1746b21dc0bc) /* 681 */,
+ U64_C(0xc7caa854f5d7cdd3) /* 682 */, U64_C(0x7cac32883d261d9c) /* 683 */,
+ U64_C(0x7690c26423ba942c) /* 684 */, U64_C(0x17e55524478042b8) /* 685 */,
+ U64_C(0xe0be477656a2389f) /* 686 */, U64_C(0x4d289b5e67ab2da0) /* 687 */,
+ U64_C(0x44862b9c8fbbfd31) /* 688 */, U64_C(0xb47cc8049d141365) /* 689 */,
+ U64_C(0x822c1b362b91c793) /* 690 */, U64_C(0x4eb14655fb13dfd8) /* 691 */,
+ U64_C(0x1ecbba0714e2a97b) /* 692 */, U64_C(0x6143459d5cde5f14) /* 693 */,
+ U64_C(0x53a8fbf1d5f0ac89) /* 694 */, U64_C(0x97ea04d81c5e5b00) /* 695 */,
+ U64_C(0x622181a8d4fdb3f3) /* 696 */, U64_C(0xe9bcd341572a1208) /* 697 */,
+ U64_C(0x1411258643cce58a) /* 698 */, U64_C(0x9144c5fea4c6e0a4) /* 699 */,
+ U64_C(0x0d33d06565cf620f) /* 700 */, U64_C(0x54a48d489f219ca1) /* 701 */,
+ U64_C(0xc43e5eac6d63c821) /* 702 */, U64_C(0xa9728b3a72770daf) /* 703 */,
+ U64_C(0xd7934e7b20df87ef) /* 704 */, U64_C(0xe35503b61a3e86e5) /* 705 */,
+ U64_C(0xcae321fbc819d504) /* 706 */, U64_C(0x129a50b3ac60bfa6) /* 707 */,
+ U64_C(0xcd5e68ea7e9fb6c3) /* 708 */, U64_C(0xb01c90199483b1c7) /* 709 */,
+ U64_C(0x3de93cd5c295376c) /* 710 */, U64_C(0xaed52edf2ab9ad13) /* 711 */,
+ U64_C(0x2e60f512c0a07884) /* 712 */, U64_C(0xbc3d86a3e36210c9) /* 713 */,
+ U64_C(0x35269d9b163951ce) /* 714 */, U64_C(0x0c7d6e2ad0cdb5fa) /* 715 */,
+ U64_C(0x59e86297d87f5733) /* 716 */, U64_C(0x298ef221898db0e7) /* 717 */,
+ U64_C(0x55000029d1a5aa7e) /* 718 */, U64_C(0x8bc08ae1b5061b45) /* 719 */,
+ U64_C(0xc2c31c2b6c92703a) /* 720 */, U64_C(0x94cc596baf25ef42) /* 721 */,
+ U64_C(0x0a1d73db22540456) /* 722 */, U64_C(0x04b6a0f9d9c4179a) /* 723 */,
+ U64_C(0xeffdafa2ae3d3c60) /* 724 */, U64_C(0xf7c8075bb49496c4) /* 725 */,
+ U64_C(0x9cc5c7141d1cd4e3) /* 726 */, U64_C(0x78bd1638218e5534) /* 727 */,
+ U64_C(0xb2f11568f850246a) /* 728 */, U64_C(0xedfabcfa9502bc29) /* 729 */,
+ U64_C(0x796ce5f2da23051b) /* 730 */, U64_C(0xaae128b0dc93537c) /* 731 */,
+ U64_C(0x3a493da0ee4b29ae) /* 732 */, U64_C(0xb5df6b2c416895d7) /* 733 */,
+ U64_C(0xfcabbd25122d7f37) /* 734 */, U64_C(0x70810b58105dc4b1) /* 735 */,
+ U64_C(0xe10fdd37f7882a90) /* 736 */, U64_C(0x524dcab5518a3f5c) /* 737 */,
+ U64_C(0x3c9e85878451255b) /* 738 */, U64_C(0x4029828119bd34e2) /* 739 */,
+ U64_C(0x74a05b6f5d3ceccb) /* 740 */, U64_C(0xb610021542e13eca) /* 741 */,
+ U64_C(0x0ff979d12f59e2ac) /* 742 */, U64_C(0x6037da27e4f9cc50) /* 743 */,
+ U64_C(0x5e92975a0df1847d) /* 744 */, U64_C(0xd66de190d3e623fe) /* 745 */,
+ U64_C(0x5032d6b87b568048) /* 746 */, U64_C(0x9a36b7ce8235216e) /* 747 */,
+ U64_C(0x80272a7a24f64b4a) /* 748 */, U64_C(0x93efed8b8c6916f7) /* 749 */,
+ U64_C(0x37ddbff44cce1555) /* 750 */, U64_C(0x4b95db5d4b99bd25) /* 751 */,
+ U64_C(0x92d3fda169812fc0) /* 752 */, U64_C(0xfb1a4a9a90660bb6) /* 753 */,
+ U64_C(0x730c196946a4b9b2) /* 754 */, U64_C(0x81e289aa7f49da68) /* 755 */,
+ U64_C(0x64669a0f83b1a05f) /* 756 */, U64_C(0x27b3ff7d9644f48b) /* 757 */,
+ U64_C(0xcc6b615c8db675b3) /* 758 */, U64_C(0x674f20b9bcebbe95) /* 759 */,
+ U64_C(0x6f31238275655982) /* 760 */, U64_C(0x5ae488713e45cf05) /* 761 */,
+ U64_C(0xbf619f9954c21157) /* 762 */, U64_C(0xeabac46040a8eae9) /* 763 */,
+ U64_C(0x454c6fe9f2c0c1cd) /* 764 */, U64_C(0x419cf6496412691c) /* 765 */,
+ U64_C(0xd3dc3bef265b0f70) /* 766 */, U64_C(0x6d0e60f5c3578a9e) /* 767 */
};
static u64 sbox4[256] = {
- 0x5b0e608526323c55LL /* 768 */, 0x1a46c1a9fa1b59f5LL /* 769 */,
- 0xa9e245a17c4c8ffaLL /* 770 */, 0x65ca5159db2955d7LL /* 771 */,
- 0x05db0a76ce35afc2LL /* 772 */, 0x81eac77ea9113d45LL /* 773 */,
- 0x528ef88ab6ac0a0dLL /* 774 */, 0xa09ea253597be3ffLL /* 775 */,
- 0x430ddfb3ac48cd56LL /* 776 */, 0xc4b3a67af45ce46fLL /* 777 */,
- 0x4ececfd8fbe2d05eLL /* 778 */, 0x3ef56f10b39935f0LL /* 779 */,
- 0x0b22d6829cd619c6LL /* 780 */, 0x17fd460a74df2069LL /* 781 */,
- 0x6cf8cc8e8510ed40LL /* 782 */, 0xd6c824bf3a6ecaa7LL /* 783 */,
- 0x61243d581a817049LL /* 784 */, 0x048bacb6bbc163a2LL /* 785 */,
- 0xd9a38ac27d44cc32LL /* 786 */, 0x7fddff5baaf410abLL /* 787 */,
- 0xad6d495aa804824bLL /* 788 */, 0xe1a6a74f2d8c9f94LL /* 789 */,
- 0xd4f7851235dee8e3LL /* 790 */, 0xfd4b7f886540d893LL /* 791 */,
- 0x247c20042aa4bfdaLL /* 792 */, 0x096ea1c517d1327cLL /* 793 */,
- 0xd56966b4361a6685LL /* 794 */, 0x277da5c31221057dLL /* 795 */,
- 0x94d59893a43acff7LL /* 796 */, 0x64f0c51ccdc02281LL /* 797 */,
- 0x3d33bcc4ff6189dbLL /* 798 */, 0xe005cb184ce66af1LL /* 799 */,
- 0xff5ccd1d1db99beaLL /* 800 */, 0xb0b854a7fe42980fLL /* 801 */,
- 0x7bd46a6a718d4b9fLL /* 802 */, 0xd10fa8cc22a5fd8cLL /* 803 */,
- 0xd31484952be4bd31LL /* 804 */, 0xc7fa975fcb243847LL /* 805 */,
- 0x4886ed1e5846c407LL /* 806 */, 0x28cddb791eb70b04LL /* 807 */,
- 0xc2b00be2f573417fLL /* 808 */, 0x5c9590452180f877LL /* 809 */,
- 0x7a6bddfff370eb00LL /* 810 */, 0xce509e38d6d9d6a4LL /* 811 */,
- 0xebeb0f00647fa702LL /* 812 */, 0x1dcc06cf76606f06LL /* 813 */,
- 0xe4d9f28ba286ff0aLL /* 814 */, 0xd85a305dc918c262LL /* 815 */,
- 0x475b1d8732225f54LL /* 816 */, 0x2d4fb51668ccb5feLL /* 817 */,
- 0xa679b9d9d72bba20LL /* 818 */, 0x53841c0d912d43a5LL /* 819 */,
- 0x3b7eaa48bf12a4e8LL /* 820 */, 0x781e0e47f22f1ddfLL /* 821 */,
- 0xeff20ce60ab50973LL /* 822 */, 0x20d261d19dffb742LL /* 823 */,
- 0x16a12b03062a2e39LL /* 824 */, 0x1960eb2239650495LL /* 825 */,
- 0x251c16fed50eb8b8LL /* 826 */, 0x9ac0c330f826016eLL /* 827 */,
- 0xed152665953e7671LL /* 828 */, 0x02d63194a6369570LL /* 829 */,
- 0x5074f08394b1c987LL /* 830 */, 0x70ba598c90b25ce1LL /* 831 */,
- 0x794a15810b9742f6LL /* 832 */, 0x0d5925e9fcaf8c6cLL /* 833 */,
- 0x3067716cd868744eLL /* 834 */, 0x910ab077e8d7731bLL /* 835 */,
- 0x6a61bbdb5ac42f61LL /* 836 */, 0x93513efbf0851567LL /* 837 */,
- 0xf494724b9e83e9d5LL /* 838 */, 0xe887e1985c09648dLL /* 839 */,
- 0x34b1d3c675370cfdLL /* 840 */, 0xdc35e433bc0d255dLL /* 841 */,
- 0xd0aab84234131be0LL /* 842 */, 0x08042a50b48b7eafLL /* 843 */,
- 0x9997c4ee44a3ab35LL /* 844 */, 0x829a7b49201799d0LL /* 845 */,
- 0x263b8307b7c54441LL /* 846 */, 0x752f95f4fd6a6ca6LL /* 847 */,
- 0x927217402c08c6e5LL /* 848 */, 0x2a8ab754a795d9eeLL /* 849 */,
- 0xa442f7552f72943dLL /* 850 */, 0x2c31334e19781208LL /* 851 */,
- 0x4fa98d7ceaee6291LL /* 852 */, 0x55c3862f665db309LL /* 853 */,
- 0xbd0610175d53b1f3LL /* 854 */, 0x46fe6cb840413f27LL /* 855 */,
- 0x3fe03792df0cfa59LL /* 856 */, 0xcfe700372eb85e8fLL /* 857 */,
- 0xa7be29e7adbce118LL /* 858 */, 0xe544ee5cde8431ddLL /* 859 */,
- 0x8a781b1b41f1873eLL /* 860 */, 0xa5c94c78a0d2f0e7LL /* 861 */,
- 0x39412e2877b60728LL /* 862 */, 0xa1265ef3afc9a62cLL /* 863 */,
- 0xbcc2770c6a2506c5LL /* 864 */, 0x3ab66dd5dce1ce12LL /* 865 */,
- 0xe65499d04a675b37LL /* 866 */, 0x7d8f523481bfd216LL /* 867 */,
- 0x0f6f64fcec15f389LL /* 868 */, 0x74efbe618b5b13c8LL /* 869 */,
- 0xacdc82b714273e1dLL /* 870 */, 0xdd40bfe003199d17LL /* 871 */,
- 0x37e99257e7e061f8LL /* 872 */, 0xfa52626904775aaaLL /* 873 */,
- 0x8bbbf63a463d56f9LL /* 874 */, 0xf0013f1543a26e64LL /* 875 */,
- 0xa8307e9f879ec898LL /* 876 */, 0xcc4c27a4150177ccLL /* 877 */,
- 0x1b432f2cca1d3348LL /* 878 */, 0xde1d1f8f9f6fa013LL /* 879 */,
- 0x606602a047a7ddd6LL /* 880 */, 0xd237ab64cc1cb2c7LL /* 881 */,
- 0x9b938e7225fcd1d3LL /* 882 */, 0xec4e03708e0ff476LL /* 883 */,
- 0xfeb2fbda3d03c12dLL /* 884 */, 0xae0bced2ee43889aLL /* 885 */,
- 0x22cb8923ebfb4f43LL /* 886 */, 0x69360d013cf7396dLL /* 887 */,
- 0x855e3602d2d4e022LL /* 888 */, 0x073805bad01f784cLL /* 889 */,
- 0x33e17a133852f546LL /* 890 */, 0xdf4874058ac7b638LL /* 891 */,
- 0xba92b29c678aa14aLL /* 892 */, 0x0ce89fc76cfaadcdLL /* 893 */,
- 0x5f9d4e0908339e34LL /* 894 */, 0xf1afe9291f5923b9LL /* 895 */,
- 0x6e3480f60f4a265fLL /* 896 */, 0xeebf3a2ab29b841cLL /* 897 */,
- 0xe21938a88f91b4adLL /* 898 */, 0x57dfeff845c6d3c3LL /* 899 */,
- 0x2f006b0bf62caaf2LL /* 900 */, 0x62f479ef6f75ee78LL /* 901 */,
- 0x11a55ad41c8916a9LL /* 902 */, 0xf229d29084fed453LL /* 903 */,
- 0x42f1c27b16b000e6LL /* 904 */, 0x2b1f76749823c074LL /* 905 */,
- 0x4b76eca3c2745360LL /* 906 */, 0x8c98f463b91691bdLL /* 907 */,
- 0x14bcc93cf1ade66aLL /* 908 */, 0x8885213e6d458397LL /* 909 */,
- 0x8e177df0274d4711LL /* 910 */, 0xb49b73b5503f2951LL /* 911 */,
- 0x10168168c3f96b6bLL /* 912 */, 0x0e3d963b63cab0aeLL /* 913 */,
- 0x8dfc4b5655a1db14LL /* 914 */, 0xf789f1356e14de5cLL /* 915 */,
- 0x683e68af4e51dac1LL /* 916 */, 0xc9a84f9d8d4b0fd9LL /* 917 */,
- 0x3691e03f52a0f9d1LL /* 918 */, 0x5ed86e46e1878e80LL /* 919 */,
- 0x3c711a0e99d07150LL /* 920 */, 0x5a0865b20c4e9310LL /* 921 */,
- 0x56fbfc1fe4f0682eLL /* 922 */, 0xea8d5de3105edf9bLL /* 923 */,
- 0x71abfdb12379187aLL /* 924 */, 0x2eb99de1bee77b9cLL /* 925 */,
- 0x21ecc0ea33cf4523LL /* 926 */, 0x59a4d7521805c7a1LL /* 927 */,
- 0x3896f5eb56ae7c72LL /* 928 */, 0xaa638f3db18f75dcLL /* 929 */,
- 0x9f39358dabe9808eLL /* 930 */, 0xb7defa91c00b72acLL /* 931 */,
- 0x6b5541fd62492d92LL /* 932 */, 0x6dc6dee8f92e4d5bLL /* 933 */,
- 0x353f57abc4beea7eLL /* 934 */, 0x735769d6da5690ceLL /* 935 */,
- 0x0a234aa642391484LL /* 936 */, 0xf6f9508028f80d9dLL /* 937 */,
- 0xb8e319a27ab3f215LL /* 938 */, 0x31ad9c1151341a4dLL /* 939 */,
- 0x773c22a57bef5805LL /* 940 */, 0x45c7561a07968633LL /* 941 */,
- 0xf913da9e249dbe36LL /* 942 */, 0xda652d9b78a64c68LL /* 943 */,
- 0x4c27a97f3bc334efLL /* 944 */, 0x76621220e66b17f4LL /* 945 */,
- 0x967743899acd7d0bLL /* 946 */, 0xf3ee5bcae0ed6782LL /* 947 */,
- 0x409f753600c879fcLL /* 948 */, 0x06d09a39b5926db6LL /* 949 */,
- 0x6f83aeb0317ac588LL /* 950 */, 0x01e6ca4a86381f21LL /* 951 */,
- 0x66ff3462d19f3025LL /* 952 */, 0x72207c24ddfd3bfbLL /* 953 */,
- 0x4af6b6d3e2ece2ebLL /* 954 */, 0x9c994dbec7ea08deLL /* 955 */,
- 0x49ace597b09a8bc4LL /* 956 */, 0xb38c4766cf0797baLL /* 957 */,
- 0x131b9373c57c2a75LL /* 958 */, 0xb1822cce61931e58LL /* 959 */,
- 0x9d7555b909ba1c0cLL /* 960 */, 0x127fafdd937d11d2LL /* 961 */,
- 0x29da3badc66d92e4LL /* 962 */, 0xa2c1d57154c2ecbcLL /* 963 */,
- 0x58c5134d82f6fe24LL /* 964 */, 0x1c3ae3515b62274fLL /* 965 */,
- 0xe907c82e01cb8126LL /* 966 */, 0xf8ed091913e37fcbLL /* 967 */,
- 0x3249d8f9c80046c9LL /* 968 */, 0x80cf9bede388fb63LL /* 969 */,
- 0x1881539a116cf19eLL /* 970 */, 0x5103f3f76bd52457LL /* 971 */,
- 0x15b7e6f5ae47f7a8LL /* 972 */, 0xdbd7c6ded47e9ccfLL /* 973 */,
- 0x44e55c410228bb1aLL /* 974 */, 0xb647d4255edb4e99LL /* 975 */,
- 0x5d11882bb8aafc30LL /* 976 */, 0xf5098bbb29d3212aLL /* 977 */,
- 0x8fb5ea14e90296b3LL /* 978 */, 0x677b942157dd025aLL /* 979 */,
- 0xfb58e7c0a390acb5LL /* 980 */, 0x89d3674c83bd4a01LL /* 981 */,
- 0x9e2da4df4bf3b93bLL /* 982 */, 0xfcc41e328cab4829LL /* 983 */,
- 0x03f38c96ba582c52LL /* 984 */, 0xcad1bdbd7fd85db2LL /* 985 */,
- 0xbbb442c16082ae83LL /* 986 */, 0xb95fe86ba5da9ab0LL /* 987 */,
- 0xb22e04673771a93fLL /* 988 */, 0x845358c9493152d8LL /* 989 */,
- 0xbe2a488697b4541eLL /* 990 */, 0x95a2dc2dd38e6966LL /* 991 */,
- 0xc02c11ac923c852bLL /* 992 */, 0x2388b1990df2a87bLL /* 993 */,
- 0x7c8008fa1b4f37beLL /* 994 */, 0x1f70d0c84d54e503LL /* 995 */,
- 0x5490adec7ece57d4LL /* 996 */, 0x002b3c27d9063a3aLL /* 997 */,
- 0x7eaea3848030a2bfLL /* 998 */, 0xc602326ded2003c0LL /* 999 */,
- 0x83a7287d69a94086LL /* 1000 */, 0xc57a5fcb30f57a8aLL /* 1001 */,
- 0xb56844e479ebe779LL /* 1002 */, 0xa373b40f05dcbce9LL /* 1003 */,
- 0xd71a786e88570ee2LL /* 1004 */, 0x879cbacdbde8f6a0LL /* 1005 */,
- 0x976ad1bcc164a32fLL /* 1006 */, 0xab21e25e9666d78bLL /* 1007 */,
- 0x901063aae5e5c33cLL /* 1008 */, 0x9818b34448698d90LL /* 1009 */,
- 0xe36487ae3e1e8abbLL /* 1010 */, 0xafbdf931893bdcb4LL /* 1011 */,
- 0x6345a0dc5fbbd519LL /* 1012 */, 0x8628fe269b9465caLL /* 1013 */,
- 0x1e5d01603f9c51ecLL /* 1014 */, 0x4de44006a15049b7LL /* 1015 */,
- 0xbf6c70e5f776cbb1LL /* 1016 */, 0x411218f2ef552bedLL /* 1017 */,
- 0xcb0c0708705a36a3LL /* 1018 */, 0xe74d14754f986044LL /* 1019 */,
- 0xcd56d9430ea8280eLL /* 1020 */, 0xc12591d7535f5065LL /* 1021 */,
- 0xc83223f1720aef96LL /* 1022 */, 0xc3a0396f7363a51fLL /* 1023 */
+ U64_C(0x5b0e608526323c55) /* 768 */, U64_C(0x1a46c1a9fa1b59f5) /* 769 */,
+ U64_C(0xa9e245a17c4c8ffa) /* 770 */, U64_C(0x65ca5159db2955d7) /* 771 */,
+ U64_C(0x05db0a76ce35afc2) /* 772 */, U64_C(0x81eac77ea9113d45) /* 773 */,
+ U64_C(0x528ef88ab6ac0a0d) /* 774 */, U64_C(0xa09ea253597be3ff) /* 775 */,
+ U64_C(0x430ddfb3ac48cd56) /* 776 */, U64_C(0xc4b3a67af45ce46f) /* 777 */,
+ U64_C(0x4ececfd8fbe2d05e) /* 778 */, U64_C(0x3ef56f10b39935f0) /* 779 */,
+ U64_C(0x0b22d6829cd619c6) /* 780 */, U64_C(0x17fd460a74df2069) /* 781 */,
+ U64_C(0x6cf8cc8e8510ed40) /* 782 */, U64_C(0xd6c824bf3a6ecaa7) /* 783 */,
+ U64_C(0x61243d581a817049) /* 784 */, U64_C(0x048bacb6bbc163a2) /* 785 */,
+ U64_C(0xd9a38ac27d44cc32) /* 786 */, U64_C(0x7fddff5baaf410ab) /* 787 */,
+ U64_C(0xad6d495aa804824b) /* 788 */, U64_C(0xe1a6a74f2d8c9f94) /* 789 */,
+ U64_C(0xd4f7851235dee8e3) /* 790 */, U64_C(0xfd4b7f886540d893) /* 791 */,
+ U64_C(0x247c20042aa4bfda) /* 792 */, U64_C(0x096ea1c517d1327c) /* 793 */,
+ U64_C(0xd56966b4361a6685) /* 794 */, U64_C(0x277da5c31221057d) /* 795 */,
+ U64_C(0x94d59893a43acff7) /* 796 */, U64_C(0x64f0c51ccdc02281) /* 797 */,
+ U64_C(0x3d33bcc4ff6189db) /* 798 */, U64_C(0xe005cb184ce66af1) /* 799 */,
+ U64_C(0xff5ccd1d1db99bea) /* 800 */, U64_C(0xb0b854a7fe42980f) /* 801 */,
+ U64_C(0x7bd46a6a718d4b9f) /* 802 */, U64_C(0xd10fa8cc22a5fd8c) /* 803 */,
+ U64_C(0xd31484952be4bd31) /* 804 */, U64_C(0xc7fa975fcb243847) /* 805 */,
+ U64_C(0x4886ed1e5846c407) /* 806 */, U64_C(0x28cddb791eb70b04) /* 807 */,
+ U64_C(0xc2b00be2f573417f) /* 808 */, U64_C(0x5c9590452180f877) /* 809 */,
+ U64_C(0x7a6bddfff370eb00) /* 810 */, U64_C(0xce509e38d6d9d6a4) /* 811 */,
+ U64_C(0xebeb0f00647fa702) /* 812 */, U64_C(0x1dcc06cf76606f06) /* 813 */,
+ U64_C(0xe4d9f28ba286ff0a) /* 814 */, U64_C(0xd85a305dc918c262) /* 815 */,
+ U64_C(0x475b1d8732225f54) /* 816 */, U64_C(0x2d4fb51668ccb5fe) /* 817 */,
+ U64_C(0xa679b9d9d72bba20) /* 818 */, U64_C(0x53841c0d912d43a5) /* 819 */,
+ U64_C(0x3b7eaa48bf12a4e8) /* 820 */, U64_C(0x781e0e47f22f1ddf) /* 821 */,
+ U64_C(0xeff20ce60ab50973) /* 822 */, U64_C(0x20d261d19dffb742) /* 823 */,
+ U64_C(0x16a12b03062a2e39) /* 824 */, U64_C(0x1960eb2239650495) /* 825 */,
+ U64_C(0x251c16fed50eb8b8) /* 826 */, U64_C(0x9ac0c330f826016e) /* 827 */,
+ U64_C(0xed152665953e7671) /* 828 */, U64_C(0x02d63194a6369570) /* 829 */,
+ U64_C(0x5074f08394b1c987) /* 830 */, U64_C(0x70ba598c90b25ce1) /* 831 */,
+ U64_C(0x794a15810b9742f6) /* 832 */, U64_C(0x0d5925e9fcaf8c6c) /* 833 */,
+ U64_C(0x3067716cd868744e) /* 834 */, U64_C(0x910ab077e8d7731b) /* 835 */,
+ U64_C(0x6a61bbdb5ac42f61) /* 836 */, U64_C(0x93513efbf0851567) /* 837 */,
+ U64_C(0xf494724b9e83e9d5) /* 838 */, U64_C(0xe887e1985c09648d) /* 839 */,
+ U64_C(0x34b1d3c675370cfd) /* 840 */, U64_C(0xdc35e433bc0d255d) /* 841 */,
+ U64_C(0xd0aab84234131be0) /* 842 */, U64_C(0x08042a50b48b7eaf) /* 843 */,
+ U64_C(0x9997c4ee44a3ab35) /* 844 */, U64_C(0x829a7b49201799d0) /* 845 */,
+ U64_C(0x263b8307b7c54441) /* 846 */, U64_C(0x752f95f4fd6a6ca6) /* 847 */,
+ U64_C(0x927217402c08c6e5) /* 848 */, U64_C(0x2a8ab754a795d9ee) /* 849 */,
+ U64_C(0xa442f7552f72943d) /* 850 */, U64_C(0x2c31334e19781208) /* 851 */,
+ U64_C(0x4fa98d7ceaee6291) /* 852 */, U64_C(0x55c3862f665db309) /* 853 */,
+ U64_C(0xbd0610175d53b1f3) /* 854 */, U64_C(0x46fe6cb840413f27) /* 855 */,
+ U64_C(0x3fe03792df0cfa59) /* 856 */, U64_C(0xcfe700372eb85e8f) /* 857 */,
+ U64_C(0xa7be29e7adbce118) /* 858 */, U64_C(0xe544ee5cde8431dd) /* 859 */,
+ U64_C(0x8a781b1b41f1873e) /* 860 */, U64_C(0xa5c94c78a0d2f0e7) /* 861 */,
+ U64_C(0x39412e2877b60728) /* 862 */, U64_C(0xa1265ef3afc9a62c) /* 863 */,
+ U64_C(0xbcc2770c6a2506c5) /* 864 */, U64_C(0x3ab66dd5dce1ce12) /* 865 */,
+ U64_C(0xe65499d04a675b37) /* 866 */, U64_C(0x7d8f523481bfd216) /* 867 */,
+ U64_C(0x0f6f64fcec15f389) /* 868 */, U64_C(0x74efbe618b5b13c8) /* 869 */,
+ U64_C(0xacdc82b714273e1d) /* 870 */, U64_C(0xdd40bfe003199d17) /* 871 */,
+ U64_C(0x37e99257e7e061f8) /* 872 */, U64_C(0xfa52626904775aaa) /* 873 */,
+ U64_C(0x8bbbf63a463d56f9) /* 874 */, U64_C(0xf0013f1543a26e64) /* 875 */,
+ U64_C(0xa8307e9f879ec898) /* 876 */, U64_C(0xcc4c27a4150177cc) /* 877 */,
+ U64_C(0x1b432f2cca1d3348) /* 878 */, U64_C(0xde1d1f8f9f6fa013) /* 879 */,
+ U64_C(0x606602a047a7ddd6) /* 880 */, U64_C(0xd237ab64cc1cb2c7) /* 881 */,
+ U64_C(0x9b938e7225fcd1d3) /* 882 */, U64_C(0xec4e03708e0ff476) /* 883 */,
+ U64_C(0xfeb2fbda3d03c12d) /* 884 */, U64_C(0xae0bced2ee43889a) /* 885 */,
+ U64_C(0x22cb8923ebfb4f43) /* 886 */, U64_C(0x69360d013cf7396d) /* 887 */,
+ U64_C(0x855e3602d2d4e022) /* 888 */, U64_C(0x073805bad01f784c) /* 889 */,
+ U64_C(0x33e17a133852f546) /* 890 */, U64_C(0xdf4874058ac7b638) /* 891 */,
+ U64_C(0xba92b29c678aa14a) /* 892 */, U64_C(0x0ce89fc76cfaadcd) /* 893 */,
+ U64_C(0x5f9d4e0908339e34) /* 894 */, U64_C(0xf1afe9291f5923b9) /* 895 */,
+ U64_C(0x6e3480f60f4a265f) /* 896 */, U64_C(0xeebf3a2ab29b841c) /* 897 */,
+ U64_C(0xe21938a88f91b4ad) /* 898 */, U64_C(0x57dfeff845c6d3c3) /* 899 */,
+ U64_C(0x2f006b0bf62caaf2) /* 900 */, U64_C(0x62f479ef6f75ee78) /* 901 */,
+ U64_C(0x11a55ad41c8916a9) /* 902 */, U64_C(0xf229d29084fed453) /* 903 */,
+ U64_C(0x42f1c27b16b000e6) /* 904 */, U64_C(0x2b1f76749823c074) /* 905 */,
+ U64_C(0x4b76eca3c2745360) /* 906 */, U64_C(0x8c98f463b91691bd) /* 907 */,
+ U64_C(0x14bcc93cf1ade66a) /* 908 */, U64_C(0x8885213e6d458397) /* 909 */,
+ U64_C(0x8e177df0274d4711) /* 910 */, U64_C(0xb49b73b5503f2951) /* 911 */,
+ U64_C(0x10168168c3f96b6b) /* 912 */, U64_C(0x0e3d963b63cab0ae) /* 913 */,
+ U64_C(0x8dfc4b5655a1db14) /* 914 */, U64_C(0xf789f1356e14de5c) /* 915 */,
+ U64_C(0x683e68af4e51dac1) /* 916 */, U64_C(0xc9a84f9d8d4b0fd9) /* 917 */,
+ U64_C(0x3691e03f52a0f9d1) /* 918 */, U64_C(0x5ed86e46e1878e80) /* 919 */,
+ U64_C(0x3c711a0e99d07150) /* 920 */, U64_C(0x5a0865b20c4e9310) /* 921 */,
+ U64_C(0x56fbfc1fe4f0682e) /* 922 */, U64_C(0xea8d5de3105edf9b) /* 923 */,
+ U64_C(0x71abfdb12379187a) /* 924 */, U64_C(0x2eb99de1bee77b9c) /* 925 */,
+ U64_C(0x21ecc0ea33cf4523) /* 926 */, U64_C(0x59a4d7521805c7a1) /* 927 */,
+ U64_C(0x3896f5eb56ae7c72) /* 928 */, U64_C(0xaa638f3db18f75dc) /* 929 */,
+ U64_C(0x9f39358dabe9808e) /* 930 */, U64_C(0xb7defa91c00b72ac) /* 931 */,
+ U64_C(0x6b5541fd62492d92) /* 932 */, U64_C(0x6dc6dee8f92e4d5b) /* 933 */,
+ U64_C(0x353f57abc4beea7e) /* 934 */, U64_C(0x735769d6da5690ce) /* 935 */,
+ U64_C(0x0a234aa642391484) /* 936 */, U64_C(0xf6f9508028f80d9d) /* 937 */,
+ U64_C(0xb8e319a27ab3f215) /* 938 */, U64_C(0x31ad9c1151341a4d) /* 939 */,
+ U64_C(0x773c22a57bef5805) /* 940 */, U64_C(0x45c7561a07968633) /* 941 */,
+ U64_C(0xf913da9e249dbe36) /* 942 */, U64_C(0xda652d9b78a64c68) /* 943 */,
+ U64_C(0x4c27a97f3bc334ef) /* 944 */, U64_C(0x76621220e66b17f4) /* 945 */,
+ U64_C(0x967743899acd7d0b) /* 946 */, U64_C(0xf3ee5bcae0ed6782) /* 947 */,
+ U64_C(0x409f753600c879fc) /* 948 */, U64_C(0x06d09a39b5926db6) /* 949 */,
+ U64_C(0x6f83aeb0317ac588) /* 950 */, U64_C(0x01e6ca4a86381f21) /* 951 */,
+ U64_C(0x66ff3462d19f3025) /* 952 */, U64_C(0x72207c24ddfd3bfb) /* 953 */,
+ U64_C(0x4af6b6d3e2ece2eb) /* 954 */, U64_C(0x9c994dbec7ea08de) /* 955 */,
+ U64_C(0x49ace597b09a8bc4) /* 956 */, U64_C(0xb38c4766cf0797ba) /* 957 */,
+ U64_C(0x131b9373c57c2a75) /* 958 */, U64_C(0xb1822cce61931e58) /* 959 */,
+ U64_C(0x9d7555b909ba1c0c) /* 960 */, U64_C(0x127fafdd937d11d2) /* 961 */,
+ U64_C(0x29da3badc66d92e4) /* 962 */, U64_C(0xa2c1d57154c2ecbc) /* 963 */,
+ U64_C(0x58c5134d82f6fe24) /* 964 */, U64_C(0x1c3ae3515b62274f) /* 965 */,
+ U64_C(0xe907c82e01cb8126) /* 966 */, U64_C(0xf8ed091913e37fcb) /* 967 */,
+ U64_C(0x3249d8f9c80046c9) /* 968 */, U64_C(0x80cf9bede388fb63) /* 969 */,
+ U64_C(0x1881539a116cf19e) /* 970 */, U64_C(0x5103f3f76bd52457) /* 971 */,
+ U64_C(0x15b7e6f5ae47f7a8) /* 972 */, U64_C(0xdbd7c6ded47e9ccf) /* 973 */,
+ U64_C(0x44e55c410228bb1a) /* 974 */, U64_C(0xb647d4255edb4e99) /* 975 */,
+ U64_C(0x5d11882bb8aafc30) /* 976 */, U64_C(0xf5098bbb29d3212a) /* 977 */,
+ U64_C(0x8fb5ea14e90296b3) /* 978 */, U64_C(0x677b942157dd025a) /* 979 */,
+ U64_C(0xfb58e7c0a390acb5) /* 980 */, U64_C(0x89d3674c83bd4a01) /* 981 */,
+ U64_C(0x9e2da4df4bf3b93b) /* 982 */, U64_C(0xfcc41e328cab4829) /* 983 */,
+ U64_C(0x03f38c96ba582c52) /* 984 */, U64_C(0xcad1bdbd7fd85db2) /* 985 */,
+ U64_C(0xbbb442c16082ae83) /* 986 */, U64_C(0xb95fe86ba5da9ab0) /* 987 */,
+ U64_C(0xb22e04673771a93f) /* 988 */, U64_C(0x845358c9493152d8) /* 989 */,
+ U64_C(0xbe2a488697b4541e) /* 990 */, U64_C(0x95a2dc2dd38e6966) /* 991 */,
+ U64_C(0xc02c11ac923c852b) /* 992 */, U64_C(0x2388b1990df2a87b) /* 993 */,
+ U64_C(0x7c8008fa1b4f37be) /* 994 */, U64_C(0x1f70d0c84d54e503) /* 995 */,
+ U64_C(0x5490adec7ece57d4) /* 996 */, U64_C(0x002b3c27d9063a3a) /* 997 */,
+ U64_C(0x7eaea3848030a2bf) /* 998 */, U64_C(0xc602326ded2003c0) /* 999 */,
+ U64_C(0x83a7287d69a94086) /* 1000 */, U64_C(0xc57a5fcb30f57a8a) /* 1001 */,
+ U64_C(0xb56844e479ebe779) /* 1002 */, U64_C(0xa373b40f05dcbce9) /* 1003 */,
+ U64_C(0xd71a786e88570ee2) /* 1004 */, U64_C(0x879cbacdbde8f6a0) /* 1005 */,
+ U64_C(0x976ad1bcc164a32f) /* 1006 */, U64_C(0xab21e25e9666d78b) /* 1007 */,
+ U64_C(0x901063aae5e5c33c) /* 1008 */, U64_C(0x9818b34448698d90) /* 1009 */,
+ U64_C(0xe36487ae3e1e8abb) /* 1010 */, U64_C(0xafbdf931893bdcb4) /* 1011 */,
+ U64_C(0x6345a0dc5fbbd519) /* 1012 */, U64_C(0x8628fe269b9465ca) /* 1013 */,
+ U64_C(0x1e5d01603f9c51ec) /* 1014 */, U64_C(0x4de44006a15049b7) /* 1015 */,
+ U64_C(0xbf6c70e5f776cbb1) /* 1016 */, U64_C(0x411218f2ef552bed) /* 1017 */,
+ U64_C(0xcb0c0708705a36a3) /* 1018 */, U64_C(0xe74d14754f986044) /* 1019 */,
+ U64_C(0xcd56d9430ea8280e) /* 1020 */, U64_C(0xc12591d7535f5065) /* 1021 */,
+ U64_C(0xc83223f1720aef96) /* 1022 */, U64_C(0xc3a0396f7363a51f) /* 1023 */
};
-
-
static void
tiger_init( void *context )
{
@@ -673,8 +670,8 @@ transform( TIGER_CONTEXT *hd, byte *data )
{
u64 a,b,c,aa,bb,cc;
u64 x[8];
- #ifdef BIG_ENDIAN_HOST
- #define MKWORD(d,n) \
+#ifdef BIG_ENDIAN_HOST
+#define MKWORD(d,n) \
( ((u64)(d)[8*(n)+7]) << 56 | ((u64)(d)[8*(n)+6]) << 48 \
| ((u64)(d)[8*(n)+5]) << 40 | ((u64)(d)[8*(n)+4]) << 32 \
| ((u64)(d)[8*(n)+3]) << 24 | ((u64)(d)[8*(n)+2]) << 16 \
@@ -687,10 +684,10 @@ transform( TIGER_CONTEXT *hd, byte *data )
x[5] = MKWORD(data, 5);
x[6] = MKWORD(data, 6);
x[7] = MKWORD(data, 7);
- #undef MKWORD
- #else
+#undef MKWORD
+#else
memcpy( &x[0], data, 64 );
- #endif
+#endif
/* save */
a = aa = hd->a;
@@ -803,18 +800,18 @@ tiger_final( void *context )
_gcry_burn_stack (21*8+11*sizeof(void*));
p = hd->buf;
- #ifdef BIG_ENDIAN_HOST
- #define X(a) do { *(u64*)p = hd->a ; p += 8; } while(0)
- #else /* little endian */
- #define X(a) do { *p++ = hd->a >> 56; *p++ = hd->a >> 48; \
+#ifdef BIG_ENDIAN_HOST
+#define X(a) do { *(u64*)p = hd->a ; p += 8; } while(0)
+#else /* little endian */
+#define X(a) do { *p++ = hd->a >> 56; *p++ = hd->a >> 48; \
*p++ = hd->a >> 40; *p++ = hd->a >> 32; \
*p++ = hd->a >> 24; *p++ = hd->a >> 16; \
*p++ = hd->a >> 8; *p++ = hd->a; } while(0)
- #endif
+#endif
X(a);
X(b);
X(c);
- #undef X
+#undef X
}
static byte *
diff --git a/cipher/twofish.c b/cipher/twofish.c
index 9795abea..a1fcef82 100644
--- a/cipher/twofish.c
+++ b/cipher/twofish.c
@@ -563,7 +563,7 @@ static byte calc_sb_tbl[512] = {
/* Perform the key setup. Note that this works only with 128- and 256-bit
* keys, despite the API that looks like it might support other sizes. */
-static int
+static gpg_err_code_t
do_twofish_setkey (TWOFISH_context *ctx, const byte *key, const unsigned keylen)
{
int i, j, k;
@@ -585,7 +585,7 @@ do_twofish_setkey (TWOFISH_context *ctx, const byte *key, const unsigned keylen)
/* Check key length. */
if( ( ( keylen - 16 ) | 16 ) != 16 )
- return GCRYERR_INV_KEYLEN;
+ return GPG_ERR_INV_KEYLEN;
/* Do self-test if necessary. */
if (!initialized) {
@@ -595,7 +595,7 @@ do_twofish_setkey (TWOFISH_context *ctx, const byte *key, const unsigned keylen)
log_error("%s\n", selftest_failed );
}
if( selftest_failed )
- return GCRYERR_SELFTEST;
+ return GPG_ERR_SELFTEST_FAILED;
/* Compute the first two words of the S vector. The magic numbers are
* the entries of the RS matrix, preprocessed through poly_to_exp. The
@@ -698,7 +698,7 @@ do_twofish_setkey (TWOFISH_context *ctx, const byte *key, const unsigned keylen)
return 0;
}
-static int
+static gpg_err_code_t
twofish_setkey (void *context, const byte *key, unsigned int keylen)
{
TWOFISH_context *ctx = (TWOFISH_context *) context;