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 #ifndef NETTLE_CBC_H_INCLUDED
0035 #define NETTLE_CBC_H_INCLUDED
0036
0037 #include "nettle-types.h"
0038 #include "aes.h"
0039
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043
0044
0045 #define cbc_encrypt nettle_cbc_encrypt
0046 #define cbc_decrypt nettle_cbc_decrypt
0047 #define cbc_aes128_encrypt nettle_cbc_aes128_encrypt
0048 #define cbc_aes192_encrypt nettle_cbc_aes192_encrypt
0049 #define cbc_aes256_encrypt nettle_cbc_aes256_encrypt
0050
0051 void
0052 cbc_encrypt(const void *ctx, nettle_cipher_func *f,
0053 size_t block_size, uint8_t *iv,
0054 size_t length, uint8_t *dst,
0055 const uint8_t *src);
0056
0057 void
0058 cbc_decrypt(const void *ctx, nettle_cipher_func *f,
0059 size_t block_size, uint8_t *iv,
0060 size_t length, uint8_t *dst,
0061 const uint8_t *src);
0062
0063 #define CBC_CTX(type, size) \
0064 { type ctx; uint8_t iv[size]; }
0065
0066 #define CBC_SET_IV(ctx, data) \
0067 memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
0068
0069
0070 #define CBC_ENCRYPT(self, f, length, dst, src) \
0071 (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
0072 (uint8_t *) 0, (const uint8_t *) 0)) \
0073 : cbc_encrypt((void *) &(self)->ctx, \
0074 (nettle_cipher_func *) (f), \
0075 sizeof((self)->iv), (self)->iv, \
0076 (length), (dst), (src)))
0077
0078 #define CBC_DECRYPT(self, f, length, dst, src) \
0079 (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
0080 (uint8_t *) 0, (const uint8_t *) 0)) \
0081 : cbc_decrypt((void *) &(self)->ctx, \
0082 (nettle_cipher_func *) (f), \
0083 sizeof((self)->iv), (self)->iv, \
0084 (length), (dst), (src)))
0085
0086 void
0087 cbc_aes128_encrypt(const struct aes128_ctx *ctx, uint8_t *iv,
0088 size_t length, uint8_t *dst, const uint8_t *src);
0089
0090 void
0091 cbc_aes192_encrypt(const struct aes192_ctx *ctx, uint8_t *iv,
0092 size_t length, uint8_t *dst, const uint8_t *src);
0093
0094 void
0095 cbc_aes256_encrypt(const struct aes256_ctx *ctx, uint8_t *iv,
0096 size_t length, uint8_t *dst, const uint8_t *src);
0097
0098 #ifdef __cplusplus
0099 }
0100 #endif
0101
0102 #endif