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
0035
0036 #ifndef NETTLE_CMAC_H_INCLUDED
0037 #define NETTLE_CMAC_H_INCLUDED
0038
0039 #include "aes.h"
0040 #include "des.h"
0041 #include "nettle-types.h"
0042
0043 #ifdef __cplusplus
0044 extern "C" {
0045 #endif
0046
0047 #define CMAC128_DIGEST_SIZE 16
0048 #define CMAC64_DIGEST_SIZE 8
0049
0050 #define cmac128_set_key nettle_cmac128_set_key
0051 #define cmac128_init nettle_cmac128_init
0052 #define cmac128_update nettle_cmac128_update
0053 #define cmac128_digest nettle_cmac128_digest
0054 #define cmac_aes128_set_key nettle_cmac_aes128_set_key
0055 #define cmac_aes128_update nettle_cmac_aes128_update
0056 #define cmac_aes128_digest nettle_cmac_aes128_digest
0057 #define cmac_aes256_set_key nettle_cmac_aes256_set_key
0058 #define cmac_aes256_update nettle_cmac_aes256_update
0059 #define cmac_aes256_digest nettle_cmac_aes256_digest
0060
0061 #define cmac64_set_key nettle_cmac64_set_key
0062 #define cmac64_init nettle_cmac64_init
0063 #define cmac64_update nettle_cmac64_update
0064 #define cmac64_digest nettle_cmac64_digest
0065 #define cmac_des3_set_key nettle_cmac_des3_set_key
0066 #define cmac_des3_update nettle_cmac_des3_update
0067 #define cmac_des3_digest nettle_cmac_des3_digest
0068
0069 struct cmac128_key
0070 {
0071 union nettle_block16 K1;
0072 union nettle_block16 K2;
0073 };
0074
0075 struct cmac128_ctx
0076 {
0077
0078 union nettle_block16 X;
0079
0080
0081 union nettle_block16 block;
0082 size_t index;
0083 };
0084
0085 struct cmac64_key
0086 {
0087 union nettle_block8 K1;
0088 union nettle_block8 K2;
0089 };
0090
0091 struct cmac64_ctx
0092 {
0093
0094 union nettle_block8 X;
0095
0096
0097 union nettle_block8 block;
0098 size_t index;
0099 };
0100
0101 void
0102 cmac128_set_key(struct cmac128_key *key, const void *cipher,
0103 nettle_cipher_func *encrypt);
0104
0105 void
0106 cmac128_init(struct cmac128_ctx *ctx);
0107
0108 void
0109 cmac128_update(struct cmac128_ctx *ctx, const void *cipher,
0110 nettle_cipher_func *encrypt,
0111 size_t msg_len, const uint8_t *msg);
0112 void
0113 cmac128_digest(struct cmac128_ctx *ctx, const struct cmac128_key *key,
0114 const void *cipher, nettle_cipher_func *encrypt,
0115 unsigned length, uint8_t *digest);
0116
0117
0118 #define CMAC128_CTX(type) \
0119 { struct cmac128_key key; struct cmac128_ctx ctx; type cipher; }
0120
0121
0122 #define CMAC128_SET_KEY(self, set_key, encrypt, cmac_key) \
0123 do { \
0124 (set_key)(&(self)->cipher, (cmac_key)); \
0125 if (0) (encrypt)(&(self)->cipher, ~(size_t) 0, \
0126 (uint8_t *) 0, (const uint8_t *) 0); \
0127 cmac128_set_key(&(self)->key, &(self)->cipher, \
0128 (nettle_cipher_func *) (encrypt)); \
0129 cmac128_init(&(self)->ctx); \
0130 } while (0)
0131
0132 #define CMAC128_UPDATE(self, encrypt, length, src) \
0133 (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
0134 (uint8_t *) 0, (const uint8_t *) 0) \
0135 : cmac128_update(&(self)->ctx, &(self)->cipher, \
0136 (nettle_cipher_func *)encrypt, \
0137 (length), (src)))
0138
0139 #define CMAC128_DIGEST(self, encrypt, length, digest) \
0140 (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
0141 (uint8_t *) 0, (const uint8_t *) 0) \
0142 : cmac128_digest(&(self)->ctx, &(self)->key, \
0143 &(self)->cipher, \
0144 (nettle_cipher_func *) (encrypt), \
0145 (length), (digest)))
0146
0147 void
0148 cmac64_set_key(struct cmac64_key *key, const void *cipher,
0149 nettle_cipher_func *encrypt);
0150
0151 void
0152 cmac64_init(struct cmac64_ctx *ctx);
0153
0154 void
0155 cmac64_update(struct cmac64_ctx *ctx, const void *cipher,
0156 nettle_cipher_func *encrypt,
0157 size_t msg_len, const uint8_t *msg);
0158
0159 void
0160 cmac64_digest(struct cmac64_ctx *ctx, const struct cmac64_key *key,
0161 const void *cipher, nettle_cipher_func *encrypt,
0162 unsigned length, uint8_t *digest);
0163
0164
0165 #define CMAC64_CTX(type) \
0166 { struct cmac64_key key; struct cmac64_ctx ctx; type cipher; }
0167
0168
0169 #define CMAC64_SET_KEY(self, set_key, encrypt, cmac_key) \
0170 do { \
0171 (set_key)(&(self)->cipher, (cmac_key)); \
0172 if (0) (encrypt)(&(self)->cipher, ~(size_t) 0, \
0173 (uint8_t *) 0, (const uint8_t *) 0); \
0174 cmac64_set_key(&(self)->key, &(self)->cipher, \
0175 (nettle_cipher_func *) (encrypt)); \
0176 cmac64_init(&(self)->ctx); \
0177 } while (0)
0178
0179 #define CMAC64_UPDATE(self, encrypt, length, src) \
0180 (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
0181 (uint8_t *) 0, (const uint8_t *) 0) \
0182 : cmac64_update(&(self)->ctx, &(self)->cipher, \
0183 (nettle_cipher_func *)encrypt, \
0184 (length), (src)))
0185
0186 #define CMAC64_DIGEST(self, encrypt, length, digest) \
0187 (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
0188 (uint8_t *) 0, (const uint8_t *) 0) \
0189 : cmac64_digest(&(self)->ctx, &(self)->key, \
0190 &(self)->cipher, \
0191 (nettle_cipher_func *) (encrypt), \
0192 (length), (digest)))
0193
0194 struct cmac_aes128_ctx CMAC128_CTX(struct aes128_ctx);
0195
0196 void
0197 cmac_aes128_set_key(struct cmac_aes128_ctx *ctx, const uint8_t *key);
0198
0199 void
0200 cmac_aes128_update(struct cmac_aes128_ctx *ctx,
0201 size_t length, const uint8_t *data);
0202
0203 void
0204 cmac_aes128_digest(struct cmac_aes128_ctx *ctx,
0205 size_t length, uint8_t *digest);
0206
0207 struct cmac_aes256_ctx CMAC128_CTX(struct aes256_ctx);
0208
0209 void
0210 cmac_aes256_set_key(struct cmac_aes256_ctx *ctx, const uint8_t *key);
0211
0212 void
0213 cmac_aes256_update(struct cmac_aes256_ctx *ctx,
0214 size_t length, const uint8_t *data);
0215
0216 void
0217 cmac_aes256_digest(struct cmac_aes256_ctx *ctx,
0218 size_t length, uint8_t *digest);
0219
0220 struct cmac_des3_ctx CMAC64_CTX(struct des3_ctx);
0221
0222 void
0223 cmac_des3_set_key(struct cmac_des3_ctx *ctx, const uint8_t *key);
0224
0225 void
0226 cmac_des3_update(struct cmac_des3_ctx *ctx,
0227 size_t length, const uint8_t *data);
0228
0229 void
0230 cmac_des3_digest(struct cmac_des3_ctx *ctx,
0231 size_t length, uint8_t *digest);
0232
0233 #ifdef __cplusplus
0234 }
0235 #endif
0236
0237 #endif