File indexing completed on 2025-01-18 10:02:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifndef NETTLE_EAX_H_INCLUDED
0035 #define NETTLE_EAX_H_INCLUDED
0036
0037 #include "aes.h"
0038
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042
0043
0044 #define eax_set_key nettle_eax_set_key
0045 #define eax_set_nonce nettle_eax_set_nonce
0046 #define eax_update nettle_eax_update
0047 #define eax_encrypt nettle_eax_encrypt
0048 #define eax_decrypt nettle_eax_decrypt
0049 #define eax_digest nettle_eax_digest
0050
0051 #define eax_aes128_set_key nettle_eax_aes128_set_key
0052 #define eax_aes128_set_nonce nettle_eax_aes128_set_nonce
0053 #define eax_aes128_update nettle_eax_aes128_update
0054 #define eax_aes128_encrypt nettle_eax_aes128_encrypt
0055 #define eax_aes128_decrypt nettle_eax_aes128_decrypt
0056 #define eax_aes128_digest nettle_eax_aes128_digest
0057
0058
0059
0060
0061 #define EAX_BLOCK_SIZE 16
0062 #define EAX_DIGEST_SIZE 16
0063
0064 #define EAX_IV_SIZE 16
0065
0066
0067 struct eax_key
0068 {
0069 union nettle_block16 pad_block;
0070 union nettle_block16 pad_partial;
0071 };
0072
0073 struct eax_ctx
0074 {
0075 union nettle_block16 omac_nonce;
0076 union nettle_block16 omac_data;
0077 union nettle_block16 omac_message;
0078 union nettle_block16 ctr;
0079 };
0080
0081 void
0082 eax_set_key (struct eax_key *key, const void *cipher, nettle_cipher_func *f);
0083
0084 void
0085 eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
0086 const void *cipher, nettle_cipher_func *f,
0087 size_t nonce_length, const uint8_t *nonce);
0088
0089 void
0090 eax_update (struct eax_ctx *eax, const struct eax_key *key,
0091 const void *cipher, nettle_cipher_func *f,
0092 size_t data_length, const uint8_t *data);
0093
0094 void
0095 eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
0096 const void *cipher, nettle_cipher_func *f,
0097 size_t length, uint8_t *dst, const uint8_t *src);
0098
0099 void
0100 eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
0101 const void *cipher, nettle_cipher_func *f,
0102 size_t length, uint8_t *dst, const uint8_t *src);
0103
0104 void
0105 eax_digest (struct eax_ctx *eax, const struct eax_key *key,
0106 const void *cipher, nettle_cipher_func *f,
0107 size_t length, uint8_t *digest);
0108
0109
0110
0111 #define EAX_CTX(type) \
0112 { struct eax_key key; struct eax_ctx eax; type cipher; }
0113
0114 #define EAX_SET_KEY(ctx, set_key, encrypt, data) \
0115 do { \
0116 (set_key)(&(ctx)->cipher, (data)); \
0117 if (0) (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
0118 (uint8_t *) 0, (const uint8_t *) 0); \
0119 eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_cipher_func *) encrypt); \
0120 } while (0)
0121
0122 #define EAX_SET_NONCE(ctx, encrypt, length, nonce) \
0123 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
0124 (uint8_t *) 0, (const uint8_t *) 0) \
0125 : eax_set_nonce (&(ctx)->eax, &(ctx)->key, \
0126 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
0127 (length), (nonce)))
0128
0129 #define EAX_UPDATE(ctx, encrypt, length, data) \
0130 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
0131 (uint8_t *) 0, (const uint8_t *) 0) \
0132 : eax_update (&(ctx)->eax, &(ctx)->key, \
0133 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
0134 (length), (data)))
0135
0136 #define EAX_ENCRYPT(ctx, encrypt, length, dst, src) \
0137 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
0138 (uint8_t *) 0, (const uint8_t *) 0) \
0139 : eax_encrypt (&(ctx)->eax, &(ctx)->key, \
0140 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
0141 (length), (dst), (src)))
0142
0143 #define EAX_DECRYPT(ctx, encrypt, length, dst, src) \
0144 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
0145 (uint8_t *) 0, (const uint8_t *) 0) \
0146 : eax_decrypt (&(ctx)->eax, &(ctx)->key, \
0147 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
0148 (length), (dst), (src)))
0149
0150 #define EAX_DIGEST(ctx, encrypt, length, digest) \
0151 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
0152 (uint8_t *) 0, (const uint8_t *) 0) \
0153 : eax_digest (&(ctx)->eax, &(ctx)->key, \
0154 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
0155 (length), (digest)))
0156
0157 struct eax_aes128_ctx EAX_CTX(struct aes128_ctx);
0158
0159 void
0160 eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key);
0161
0162 void
0163 eax_aes128_set_nonce(struct eax_aes128_ctx *ctx,
0164 size_t length, const uint8_t *iv);
0165
0166 void
0167 eax_aes128_update(struct eax_aes128_ctx *ctx,
0168 size_t length, const uint8_t *data);
0169
0170 void
0171 eax_aes128_encrypt(struct eax_aes128_ctx *ctx,
0172 size_t length, uint8_t *dst, const uint8_t *src);
0173
0174 void
0175 eax_aes128_decrypt(struct eax_aes128_ctx *ctx,
0176 size_t length, uint8_t *dst, const uint8_t *src);
0177
0178 void
0179 eax_aes128_digest(struct eax_aes128_ctx *ctx, size_t length, uint8_t *digest);
0180
0181 #ifdef __cplusplus
0182 }
0183 #endif
0184
0185 #endif