File indexing completed on 2025-01-18 10:02:14
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
0037
0038
0039
0040
0041
0042
0043
0044
0045 #ifndef NETTLE_CCM_H_INCLUDED
0046 #define NETTLE_CCM_H_INCLUDED
0047
0048 #include "aes.h"
0049
0050 #ifdef __cplusplus
0051 extern "C" {
0052 #endif
0053
0054
0055 #define ccm_set_nonce nettle_ccm_set_nonce
0056 #define ccm_update nettle_ccm_update
0057 #define ccm_encrypt nettle_ccm_encrypt
0058 #define ccm_decrypt nettle_ccm_decrypt
0059 #define ccm_digest nettle_ccm_digest
0060 #define ccm_encrypt_message nettle_ccm_encrypt_message
0061 #define ccm_decrypt_message nettle_ccm_decrypt_message
0062
0063 #define ccm_aes128_set_key nettle_ccm_aes128_set_key
0064 #define ccm_aes128_set_nonce nettle_ccm_aes128_set_nonce
0065 #define ccm_aes128_update nettle_ccm_aes128_update
0066 #define ccm_aes128_encrypt nettle_ccm_aes128_encrypt
0067 #define ccm_aes128_decrypt nettle_ccm_aes128_decrypt
0068 #define ccm_aes128_digest nettle_ccm_aes128_digest
0069 #define ccm_aes128_encrypt_message nettle_ccm_aes128_encrypt_message
0070 #define ccm_aes128_decrypt_message nettle_ccm_aes128_decrypt_message
0071
0072 #define ccm_aes192_set_key nettle_ccm_aes192_set_key
0073 #define ccm_aes192_set_nonce nettle_ccm_aes192_set_nonce
0074 #define ccm_aes192_update nettle_ccm_aes192_update
0075 #define ccm_aes192_encrypt nettle_ccm_aes192_encrypt
0076 #define ccm_aes192_decrypt nettle_ccm_aes192_decrypt
0077 #define ccm_aes192_digest nettle_ccm_aes192_digest
0078 #define ccm_aes192_encrypt_message nettle_ccm_aes192_encrypt_message
0079 #define ccm_aes192_decrypt_message nettle_ccm_aes192_decrypt_message
0080
0081 #define ccm_aes256_set_key nettle_ccm_aes256_set_key
0082 #define ccm_aes256_set_nonce nettle_ccm_aes256_set_nonce
0083 #define ccm_aes256_update nettle_ccm_aes256_update
0084 #define ccm_aes256_encrypt nettle_ccm_aes256_encrypt
0085 #define ccm_aes256_decrypt nettle_ccm_aes256_decrypt
0086 #define ccm_aes256_digest nettle_ccm_aes256_digest
0087 #define ccm_aes256_encrypt_message nettle_ccm_aes256_encrypt_message
0088 #define ccm_aes256_decrypt_message nettle_ccm_aes256_decrypt_message
0089
0090
0091 #define CCM_BLOCK_SIZE 16
0092 #define CCM_DIGEST_SIZE 16
0093 #define CCM_MIN_NONCE_SIZE 7
0094 #define CCM_MAX_NONCE_SIZE 14
0095
0096
0097
0098
0099 #define CCM_MAX_MSG_SIZE(N) \
0100 ((sizeof(size_t) + (N) <= 15) \
0101 ? ~(size_t) 0 \
0102 : ((size_t) 1 << (8*(15 - N))) - 1)
0103
0104
0105 struct ccm_ctx {
0106 union nettle_block16 ctr;
0107 union nettle_block16 tag;
0108
0109 unsigned int blength;
0110 };
0111
0112
0113
0114
0115
0116 void
0117 ccm_set_nonce(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
0118 size_t noncelen, const uint8_t *nonce,
0119 size_t authlen, size_t msglen, size_t taglen);
0120
0121 void
0122 ccm_update(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
0123 size_t length, const uint8_t *data);
0124
0125 void
0126 ccm_encrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
0127 size_t length, uint8_t *dst, const uint8_t *src);
0128
0129 void
0130 ccm_decrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
0131 size_t length, uint8_t *dst, const uint8_t *src);
0132
0133 void
0134 ccm_digest(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
0135 size_t length, uint8_t *digest);
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 void
0147 ccm_encrypt_message(const void *cipher, nettle_cipher_func *f,
0148 size_t nlength, const uint8_t *nonce,
0149 size_t alength, const uint8_t *adata,
0150 size_t tlength,
0151 size_t clength, uint8_t *dst, const uint8_t *src);
0152
0153
0154
0155
0156
0157
0158
0159 int
0160 ccm_decrypt_message(const void *cipher, nettle_cipher_func *f,
0161 size_t nlength, const uint8_t *nonce,
0162 size_t alength, const uint8_t *adata,
0163 size_t tlength,
0164 size_t mlength, uint8_t *dst, const uint8_t *src);
0165
0166
0167 struct ccm_aes128_ctx {
0168 struct ccm_ctx ccm;
0169 struct aes128_ctx cipher;
0170 };
0171
0172 void
0173 ccm_aes128_set_key(struct ccm_aes128_ctx *ctx, const uint8_t *key);
0174
0175 void
0176 ccm_aes128_set_nonce(struct ccm_aes128_ctx *ctx,
0177 size_t length, const uint8_t *nonce,
0178 size_t authlen, size_t msglen, size_t taglen);
0179
0180 void
0181 ccm_aes128_update (struct ccm_aes128_ctx *ctx,
0182 size_t length, const uint8_t *data);
0183
0184 void
0185 ccm_aes128_encrypt(struct ccm_aes128_ctx *ctx,
0186 size_t length, uint8_t *dst, const uint8_t *src);
0187
0188 void
0189 ccm_aes128_decrypt(struct ccm_aes128_ctx *ctx,
0190 size_t length, uint8_t *dst, const uint8_t *src);
0191
0192 void
0193 ccm_aes128_digest(struct ccm_aes128_ctx *ctx,
0194 size_t length, uint8_t *digest);
0195
0196
0197
0198
0199 void
0200 ccm_aes128_encrypt_message(struct ccm_aes128_ctx *ctx,
0201 size_t nlength, const uint8_t *nonce,
0202 size_t alength, const uint8_t *adata,
0203 size_t tlength,
0204 size_t clength, uint8_t *dst, const uint8_t *src);
0205
0206 int
0207 ccm_aes128_decrypt_message(struct ccm_aes128_ctx *ctx,
0208 size_t nlength, const uint8_t *nonce,
0209 size_t alength, const uint8_t *adata,
0210 size_t tlength,
0211 size_t mlength, uint8_t *dst, const uint8_t *src);
0212
0213 struct ccm_aes192_ctx {
0214 struct ccm_ctx ccm;
0215 struct aes192_ctx cipher;
0216 };
0217
0218
0219 void
0220 ccm_aes192_set_key(struct ccm_aes192_ctx *ctx, const uint8_t *key);
0221
0222 void
0223 ccm_aes192_set_nonce(struct ccm_aes192_ctx *ctx,
0224 size_t length, const uint8_t *nonce,
0225 size_t authlen, size_t msglen, size_t taglen);
0226
0227 void
0228 ccm_aes192_update(struct ccm_aes192_ctx *ctx,
0229 size_t length, const uint8_t *data);
0230
0231 void
0232 ccm_aes192_encrypt(struct ccm_aes192_ctx *ctx,
0233 size_t length, uint8_t *dst, const uint8_t *src);
0234
0235 void
0236 ccm_aes192_decrypt(struct ccm_aes192_ctx *ctx,
0237 size_t length, uint8_t *dst, const uint8_t *src);
0238
0239 void
0240 ccm_aes192_digest(struct ccm_aes192_ctx *ctx,
0241 size_t length, uint8_t *digest);
0242
0243 void
0244 ccm_aes192_encrypt_message(struct ccm_aes192_ctx *ctx,
0245 size_t nlength, const uint8_t *nonce,
0246 size_t alength, const uint8_t *adata,
0247 size_t tlength,
0248 size_t clength, uint8_t *dst, const uint8_t *src);
0249
0250 int
0251 ccm_aes192_decrypt_message(struct ccm_aes192_ctx *ctx,
0252 size_t nlength, const uint8_t *nonce,
0253 size_t alength, const uint8_t *adata,
0254 size_t tlength,
0255 size_t mlength, uint8_t *dst, const uint8_t *src);
0256
0257
0258 struct ccm_aes256_ctx {
0259 struct ccm_ctx ccm;
0260 struct aes256_ctx cipher;
0261 };
0262
0263 void
0264 ccm_aes256_set_key(struct ccm_aes256_ctx *ctx, const uint8_t *key);
0265
0266 void
0267 ccm_aes256_set_nonce(struct ccm_aes256_ctx *ctx,
0268 size_t length, const uint8_t *nonce,
0269 size_t authlen, size_t msglen, size_t taglen);
0270
0271 void
0272 ccm_aes256_update(struct ccm_aes256_ctx *ctx,
0273 size_t length, const uint8_t *data);
0274
0275 void
0276 ccm_aes256_encrypt(struct ccm_aes256_ctx *ctx,
0277 size_t length, uint8_t *dst, const uint8_t *src);
0278
0279 void
0280 ccm_aes256_decrypt(struct ccm_aes256_ctx *ctx,
0281 size_t length, uint8_t *dst, const uint8_t *src);
0282
0283 void
0284 ccm_aes256_digest(struct ccm_aes256_ctx *ctx,
0285 size_t length, uint8_t *digest);
0286
0287 void
0288 ccm_aes256_encrypt_message(struct ccm_aes256_ctx *ctx,
0289 size_t nlength, const uint8_t *nonce,
0290 size_t alength, const uint8_t *adata,
0291 size_t tlength,
0292 size_t clength, uint8_t *dst, const uint8_t *src);
0293
0294 int
0295 ccm_aes256_decrypt_message(struct ccm_aes256_ctx *ctx,
0296 size_t nlength, const uint8_t *nonce,
0297 size_t alength, const uint8_t *adata,
0298 size_t tlength,
0299 size_t mlength, uint8_t *dst, const uint8_t *src);
0300
0301 #ifdef __cplusplus
0302 }
0303 #endif
0304
0305 #endif