non-pointer types, so that the types can be used to declare functions.
Updated all users.
Rev: nettle/arcfour-meta.c:1.2
Rev: nettle/cbc.h:1.2
Rev: nettle/des-compat.c:1.2
Rev: nettle/examples/nettle-benchmark.c:1.3
Rev: nettle/examples/nettle-openssl.c:1.2
Rev: nettle/examples/rsa-encrypt.c:1.2
Rev: nettle/examples/rsa-keygen.c:1.2
Rev: nettle/nettle-internal.c:1.2
Rev: nettle/nettle-meta.h:1.2
Rev: nettle/nettle-types.h:1.2
Rev: nettle/testsuite/dsa-keygen-test.c:1.3
Rev: nettle/testsuite/rsa-encrypt-test.c:1.3
Rev: nettle/testsuite/rsa-keygen-test.c:1.3
Rev: nettle/testsuite/testutils.c:1.3
const struct nettle_cipher nettle_arcfour128 =
{ "arcfour128", sizeof(struct arcfour_ctx),
0, 16,
- (nettle_set_key_func) arcfour_set_key,
- (nettle_set_key_func) arcfour_set_key,
- (nettle_crypt_func) arcfour_crypt,
- (nettle_crypt_func) arcfour_crypt
+ (nettle_set_key_func *) arcfour_set_key,
+ (nettle_set_key_func *) arcfour_set_key,
+ (nettle_crypt_func *) arcfour_crypt,
+ (nettle_crypt_func *) arcfour_crypt
};
#define CBC_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, NULL, NULL)) \
: cbc_encrypt((void *) &(self)->ctx, \
- (nettle_crypt_func) (f), \
+ (nettle_crypt_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#define CBC_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, NULL, NULL)) \
: cbc_decrypt((void *) &(self)->ctx, \
- (nettle_crypt_func) (f), \
+ (nettle_crypt_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
switch (enc)
{
case DES_ENCRYPT:
- nettle_cbc_encrypt(ctx, (nettle_crypt_func) des_encrypt,
+ nettle_cbc_encrypt(ctx, (nettle_crypt_func *) des_encrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
case DES_DECRYPT:
nettle_cbc_decrypt(ctx,
- (nettle_crypt_func) des_decrypt,
+ (nettle_crypt_func *) des_decrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
switch (enc)
{
case DES_ENCRYPT:
- nettle_cbc_encrypt(&keys, (nettle_crypt_func) des_compat_des3_encrypt,
+ nettle_cbc_encrypt(&keys, (nettle_crypt_func *) des_compat_des3_encrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
case DES_DECRYPT:
- nettle_cbc_decrypt(&keys, (nettle_crypt_func) des_compat_des3_decrypt,
+ nettle_cbc_decrypt(&keys, (nettle_crypt_func *) des_compat_des3_decrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
struct bench_hash_info
{
void *ctx;
- nettle_hash_update_func update;
+ nettle_hash_update_func *update;
const uint8_t *data;
};
struct bench_cipher_info
{
void *ctx;
- nettle_crypt_func crypt;
+ nettle_crypt_func *crypt;
uint8_t *data;
};
struct bench_cbc_info
{
void *ctx;
- nettle_crypt_func crypt;
+ nettle_crypt_func *crypt;
uint8_t *data;
/* AES */
-
+static nettle_set_key_func openssl_aes_set_encrypt_key;
static void
openssl_aes_set_encrypt_key(void *ctx, unsigned length, const uint8_t *key)
{
AES_set_encrypt_key(key, length * 8, ctx);
}
+static nettle_set_key_func openssl_aes_set_decrypt_key;
static void
openssl_aes_set_decrypt_key(void *ctx, unsigned length, const uint8_t *key)
{
AES_set_decrypt_key(key, length * 8, ctx);
}
-
+static nettle_crypt_func openssl_aes_encrypt;
static void
openssl_aes_encrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
}
}
+static nettle_crypt_func openssl_aes_decrypt;
static void
openssl_aes_decrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
};
/* Arcfour */
-
+static nettle_set_key_func openssl_arcfour_set_key;
static void
openssl_arcfour_set_key(void *ctx, unsigned length, const uint8_t *key)
{
RC4_set_key(ctx, length, key);
}
-
+static nettle_crypt_func openssl_arcfour_crypt;
static void
openssl_arcfour_crypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
};
/* Blowfish */
+static nettle_set_key_func openssl_bf_set_key;
static void
openssl_bf_set_key(void *ctx, unsigned length, const uint8_t *key)
{
BF_set_key(ctx, length, key);
}
-
+static nettle_crypt_func openssl_bf_encrypt;
static void
openssl_bf_encrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
}
}
+static nettle_crypt_func openssl_bf_decrypt;
static void
openssl_bf_decrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
/* DES */
+static nettle_set_key_func openssl_des_set_key;
static void
openssl_des_set_key(void *ctx, unsigned length, const uint8_t *key)
{
#define DES_BLOCK_SIZE 8
+static nettle_crypt_func openssl_des_encrypt;
static void
openssl_des_encrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
}
}
+static nettle_crypt_func openssl_des_decrypt;
static void
openssl_des_decrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
/* Cast128 */
+static nettle_set_key_func openssl_cast_set_key;
static void
openssl_cast_set_key(void *ctx, unsigned length, const uint8_t *key)
{
CAST_set_key(ctx, length, key);
}
+static nettle_crypt_func openssl_cast_encrypt;
static void
openssl_cast_encrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
}
}
+static nettle_crypt_func openssl_cast_decrypt;
static void
openssl_cast_decrypt(void *ctx, unsigned length,
uint8_t *dst, const uint8_t *src)
/* Hash functions */
/* md5 */
-
+static nettle_hash_init_func openssl_md5_init;
static void
openssl_md5_init(void *ctx)
{
MD5_Init(ctx);
}
+static nettle_hash_update_func openssl_md5_update;
static void
openssl_md5_update(void *ctx,
unsigned length,
MD5_Update(ctx, src, length);
}
+static nettle_hash_digest_func openssl_md5_digest;
static void
openssl_md5_digest(void *ctx,
unsigned length, uint8_t *dst)
};
/* sha1 */
-
+static nettle_hash_init_func openssl_sha1_init;
static void
openssl_sha1_init(void *ctx)
{
SHA1_Init(ctx);
}
+static nettle_hash_update_func openssl_sha1_update;
static void
openssl_sha1_update(void *ctx,
unsigned length,
SHA1_Update(ctx, src, length);
}
+static nettle_hash_digest_func openssl_sha1_digest;
static void
openssl_sha1_digest(void *ctx,
unsigned length, uint8_t *dst)
mpz_init(x);
if (!rsa_encrypt(&key,
- &ctx.yarrow, (nettle_random_func) yarrow256_random,
+ &ctx.yarrow, (nettle_random_func *) yarrow256_random,
sizeof(info.key), info.key,
x))
{
if (!rsa_generate_keypair
(&pub, &priv,
- (void *) &yarrow, (nettle_random_func) yarrow256_random,
+ (void *) &yarrow, (nettle_random_func *) yarrow256_random,
NULL, progress,
KEYSIZE, ESIZE))
{
"des", sizeof(struct des_ctx),
DES_BLOCK_SIZE, DES_KEY_SIZE,
des_set_key_hack, des_set_key_hack,
- (nettle_crypt_func) des_encrypt,
- (nettle_crypt_func) des_decrypt
+ (nettle_crypt_func *) des_encrypt,
+ (nettle_crypt_func *) des_decrypt
};
const struct nettle_cipher
"des3", sizeof(struct des3_ctx),
DES3_BLOCK_SIZE, DES3_KEY_SIZE,
des3_set_key_hack, des3_set_key_hack,
- (nettle_crypt_func) des3_encrypt,
- (nettle_crypt_func) des3_decrypt
+ (nettle_crypt_func *) des3_encrypt,
+ (nettle_crypt_func *) des3_decrypt
};
/* NOTE: This is not as nice as one might think, as it will crash if
extern "C" {
#endif
-/* Randomness. Used by key generation and dsa signature creation. */
-typedef void (*nettle_random_func)(void *ctx,
- unsigned length, uint8_t *dst);
-
-/* Progress report function, mainly for key generation. */
-typedef void (*nettle_progress_func)(void *ctx,
- int c);
-
-/* Ciphers */
-typedef void (*nettle_set_key_func)(void *ctx,
- unsigned length,
- const uint8_t *key);
-
struct nettle_cipher
{
/* Suggested key size; other sizes are sometimes possible. */
unsigned key_size;
- nettle_set_key_func set_encrypt_key;
- nettle_set_key_func set_decrypt_key;
+ nettle_set_key_func *set_encrypt_key;
+ nettle_set_key_func *set_decrypt_key;
- nettle_crypt_func encrypt;
- nettle_crypt_func decrypt;
+ nettle_crypt_func *encrypt;
+ nettle_crypt_func *decrypt;
};
#define _NETTLE_CIPHER(name, NAME, keysize) { \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
keysize / 8, \
- (nettle_set_key_func) name##_set_key, \
- (nettle_set_key_func) name##_set_key, \
- (nettle_crypt_func) name##_encrypt, \
- (nettle_crypt_func) name##_decrypt, \
+ (nettle_set_key_func *) name##_set_key, \
+ (nettle_set_key_func *) name##_set_key, \
+ (nettle_crypt_func *) name##_encrypt, \
+ (nettle_crypt_func *) name##_decrypt, \
}
#define _NETTLE_CIPHER_SEP(name, NAME, keysize) { \
- #name #keysize, \
- sizeof(struct name##_ctx), \
- NAME##_BLOCK_SIZE, \
- keysize / 8, \
- (nettle_set_key_func) name##_set_encrypt_key, \
- (nettle_set_key_func) name##_set_decrypt_key, \
- (nettle_crypt_func) name##_encrypt, \
- (nettle_crypt_func) name##_decrypt, \
+ #name #keysize, \
+ sizeof(struct name##_ctx), \
+ NAME##_BLOCK_SIZE, \
+ keysize / 8, \
+ (nettle_set_key_func *) name##_set_encrypt_key, \
+ (nettle_set_key_func *) name##_set_decrypt_key, \
+ (nettle_crypt_func *) name##_encrypt, \
+ (nettle_crypt_func *) name##_decrypt, \
}
#define _NETTLE_CIPHER_FIX(name, NAME, keysize) { \
- #name, \
- sizeof(struct name##_ctx), \
- NAME##_BLOCK_SIZE, \
- keysize / 8, \
- (nettle_set_key_func) name##_set_key, \
- (nettle_set_key_func) name##_set_key, \
- (nettle_crypt_func) name##_encrypt, \
- (nettle_crypt_func) name##_decrypt, \
+ #name, \
+ sizeof(struct name##_ctx), \
+ NAME##_BLOCK_SIZE, \
+ keysize / 8, \
+ (nettle_set_key_func *) name##_set_key, \
+ (nettle_set_key_func *) name##_set_key, \
+ (nettle_crypt_func *) name##_encrypt, \
+ (nettle_crypt_func *) name##_decrypt, \
}
extern const struct nettle_cipher nettle_aes128;
extern const struct nettle_cipher nettle_arctwo128;
extern const struct nettle_cipher nettle_arctwo_gutmann128;
-
-/* Hash algorithms */
-typedef void (*nettle_hash_init_func)(void *ctx);
-typedef void (*nettle_hash_update_func)(void *ctx,
- unsigned length,
- const uint8_t *src);
-typedef void (*nettle_hash_digest_func)(void *ctx,
- unsigned length, uint8_t *dst);
-
struct nettle_hash
{
const char *name;
/* Internal block size */
unsigned block_size;
- nettle_hash_init_func init;
- nettle_hash_update_func update;
- nettle_hash_digest_func digest;
+ nettle_hash_init_func *init;
+ nettle_hash_update_func *update;
+ nettle_hash_digest_func *digest;
};
#define _NETTLE_HASH(name, NAME) { \
sizeof(struct name##_ctx), \
NAME##_DIGEST_SIZE, \
NAME##_DATA_SIZE, \
- (nettle_hash_init_func) name##_init, \
- (nettle_hash_update_func) name##_update, \
- (nettle_hash_digest_func) name##_digest \
+ (nettle_hash_init_func *) name##_init, \
+ (nettle_hash_update_func *) name##_update, \
+ (nettle_hash_digest_func *) name##_digest \
}
extern const struct nettle_hash nettle_md2;
extern const struct nettle_hash nettle_sha1;
extern const struct nettle_hash nettle_sha256;
-
-/* ASCII armor codecs. NOTE: Experimental and subject to change. */
-
-typedef unsigned (*nettle_armor_length_func)(unsigned length);
-typedef void (*nettle_armor_init_func)(void *ctx);
-
-typedef unsigned (*nettle_armor_encode_update_func)(void *ctx,
- uint8_t *dst,
- unsigned src_length,
- const uint8_t *src);
-
-typedef unsigned (*nettle_armor_encode_final_func)(void *ctx, uint8_t *dst);
-
-typedef int (*nettle_armor_decode_update_func)(void *ctx,
- unsigned *dst_length,
- uint8_t *dst,
- unsigned src_length,
- const uint8_t *src);
-
-typedef int (*nettle_armor_decode_final_func)(void *ctx);
-
struct nettle_armor
{
const char *name;
unsigned encode_final_length;
- nettle_armor_init_func encode_init;
- nettle_armor_length_func encode_length;
- nettle_armor_encode_update_func encode_update;
- nettle_armor_encode_final_func encode_final;
+ nettle_armor_init_func *encode_init;
+ nettle_armor_length_func *encode_length;
+ nettle_armor_encode_update_func *encode_update;
+ nettle_armor_encode_final_func *encode_final;
- nettle_armor_init_func decode_init;
- nettle_armor_length_func decode_length;
- nettle_armor_decode_update_func decode_update;
- nettle_armor_decode_final_func decode_final;
+ nettle_armor_init_func *decode_init;
+ nettle_armor_length_func *decode_length;
+ nettle_armor_decode_update_func *decode_update;
+ nettle_armor_decode_final_func *decode_final;
};
#define _NETTLE_ARMOR(name, NAME) { \
sizeof(struct name##_encode_ctx), \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
- (nettle_armor_init_func) name##_encode_init, \
- (nettle_armor_length_func) name##_encode_length, \
- (nettle_armor_encode_update_func) name##_encode_update, \
- (nettle_armor_encode_final_func) name##_encode_final, \
- (nettle_armor_init_func) name##_decode_init, \
- (nettle_armor_length_func) name##_decode_length, \
- (nettle_armor_decode_update_func) name##_decode_update, \
- (nettle_armor_decode_final_func) name##_decode_final, \
+ (nettle_armor_init_func *) name##_encode_init, \
+ (nettle_armor_length_func *) name##_encode_length, \
+ (nettle_armor_encode_update_func *) name##_encode_update, \
+ (nettle_armor_encode_final_func *) name##_encode_final, \
+ (nettle_armor_init_func *) name##_decode_init, \
+ (nettle_armor_length_func *) name##_decode_length, \
+ (nettle_armor_decode_update_func *) name##_decode_update, \
+ (nettle_armor_decode_final_func *) name##_decode_final, \
}
#define _NETTLE_ARMOR_0(name, NAME) { \
0, \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
- (nettle_armor_init_func) name##_encode_init, \
- (nettle_armor_length_func) name##_encode_length, \
- (nettle_armor_encode_update_func) name##_encode_update, \
- (nettle_armor_encode_final_func) name##_encode_final, \
- (nettle_armor_init_func) name##_decode_init, \
- (nettle_armor_length_func) name##_decode_length, \
- (nettle_armor_decode_update_func) name##_decode_update, \
- (nettle_armor_decode_final_func) name##_decode_final, \
+ (nettle_armor_init_func *) name##_encode_init, \
+ (nettle_armor_length_func *) name##_encode_length, \
+ (nettle_armor_encode_update_func *) name##_encode_update, \
+ (nettle_armor_encode_final_func *) name##_encode_final, \
+ (nettle_armor_init_func *) name##_decode_init, \
+ (nettle_armor_length_func *) name##_decode_length, \
+ (nettle_armor_decode_update_func *) name##_decode_update, \
+ (nettle_armor_decode_final_func *) name##_decode_final, \
}
-
extern const struct nettle_armor nettle_base64;
extern const struct nettle_armor nettle_base16;
extern "C" {
#endif
+/* Randomness. Used by key generation and dsa signature creation. */
+typedef void (nettle_random_func)(void *ctx,
+ unsigned length, uint8_t *dst);
+
+/* Progress report function, mainly for key generation. */
+typedef void (nettle_progress_func)(void *ctx,
+ int c);
+
+/* Ciphers */
+typedef void (nettle_set_key_func)(void *ctx,
+ unsigned length,
+ const uint8_t *key);
+
/* Uses a void * for cipher contexts.
For block ciphers it would make sense with a const void * for the
context, but we use the same typedef for stream ciphers where the
internal state changes during the encryption. */
-typedef void (*nettle_crypt_func)(void *ctx,
- unsigned length, uint8_t *dst,
- const uint8_t *src);
+typedef void (nettle_crypt_func)(void *ctx,
+ unsigned length, uint8_t *dst,
+ const uint8_t *src);
+
+/* Hash algorithms */
+typedef void (nettle_hash_init_func)(void *ctx);
+typedef void (nettle_hash_update_func)(void *ctx,
+ unsigned length,
+ const uint8_t *src);
+typedef void (nettle_hash_digest_func)(void *ctx,
+ unsigned length, uint8_t *dst);
+
+/* ASCII armor codecs. NOTE: Experimental and subject to change. */
+
+typedef unsigned (nettle_armor_length_func)(unsigned length);
+typedef void (nettle_armor_init_func)(void *ctx);
+
+typedef unsigned (nettle_armor_encode_update_func)(void *ctx,
+ uint8_t *dst,
+ unsigned src_length,
+ const uint8_t *src);
+
+typedef unsigned (nettle_armor_encode_final_func)(void *ctx, uint8_t *dst);
+
+typedef int (nettle_armor_decode_update_func)(void *ctx,
+ unsigned *dst_length,
+ uint8_t *dst,
+ unsigned src_length,
+ const uint8_t *src);
-/* FIXME: Move more of the typedefs to this file? */
+typedef int (nettle_armor_decode_final_func)(void *ctx);
#ifdef __cplusplus
}
knuth_lfib_init(&lfib, 13);
if (!dsa_generate_keypair(&pub, &key,
- &lfib, (nettle_random_func) knuth_lfib_random,
+ &lfib, (nettle_random_func *) knuth_lfib_random,
NULL, verbose ? progress : NULL,
1024))
FAIL();
fprintf(stderr, "msg: `%s', length = %d\n", msg, msg_length);
ASSERT(rsa_encrypt(&pub,
- &lfib, (nettle_random_func) knuth_lfib_random,
+ &lfib, (nettle_random_func *) knuth_lfib_random,
msg_length, msg,
gibberish));
knuth_lfib_init(&lfib, 13);
if (!rsa_generate_keypair(&pub, &key,
- &lfib, (nettle_random_func) knuth_lfib_random,
+ &lfib, (nettle_random_func *) knuth_lfib_random,
NULL, verbose ? progress : NULL,
1024, 50))
FAIL();
mpz_set_ui(pub.e, 17);
if (!rsa_generate_keypair(&pub, &key,
- &lfib, (nettle_random_func) knuth_lfib_random,
+ &lfib, (nettle_random_func *) knuth_lfib_random,
NULL, verbose ? progress : NULL,
2000, 0))
FAIL();
cipher->encrypt(ctx, length, data, cleartext);
if (!MEMEQ(length, data, ciphertext))
- FAIL();
-
+ {
+ fprintf(stderr, "Encrypt failed:\nInput:");
+ print_hex(length, cleartext);
+ fprintf(stderr, "\nOutput: ");
+ print_hex(length, data);
+ fprintf(stderr, "\nExpected:");
+ print_hex(length, ciphertext);
+ fprintf(stderr, "\n");
+ FAIL();
+ }
cipher->set_decrypt_key(ctx, key_length, key);
cipher->decrypt(ctx, length, data, data);
if (!MEMEQ(length, data, cleartext))
- FAIL();
+ {
+ fprintf(stderr, "Decrypt failed:\nInput:");
+ print_hex(length, ciphertext);
+ fprintf(stderr, "\nOutput: ");
+ print_hex(length, data);
+ fprintf(stderr, "\nExpected:");
+ print_hex(length, cleartext);
+ fprintf(stderr, "\n");
+ FAIL();
+ }
free(ctx);
free(data);
sha1_update(&sha1, LDATA("The magic words are squeamish ossifrage"));
dsa_sign(pub, key,
- &lfib, (nettle_random_func) knuth_lfib_random,
+ &lfib, (nettle_random_func *) knuth_lfib_random,
&sha1, &signature);
if (verbose)