File indexing completed on 2025-10-31 09:06:40
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_OCB_H_INCLUDED
0035 #define NETTLE_OCB_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 ocb_set_key nettle_ocb_set_key
0046 #define ocb_set_nonce nettle_ocb_set_nonce
0047 #define ocb_update nettle_ocb_update
0048 #define ocb_encrypt nettle_ocb_encrypt
0049 #define ocb_decrypt nettle_ocb_decrypt
0050 #define ocb_digest nettle_ocb_digest
0051 #define ocb_encrypt_message nettle_ocb_encrypt_message
0052 #define ocb_decrypt_message nettle_ocb_decrypt_message
0053 #define ocb_aes128_set_encrypt_key nettle_ocb_aes128_set_encrypt_key
0054 #define ocb_aes128_set_decrypt_key nettle_ocb_aes128_set_decrypt_key
0055 #define ocb_aes128_set_nonce nettle_ocb_aes128_set_nonce
0056 #define ocb_aes128_update nettle_ocb_aes128_update
0057 #define ocb_aes128_encrypt nettle_ocb_aes128_encrypt
0058 #define ocb_aes128_decrypt nettle_ocb_aes128_decrypt
0059 #define ocb_aes128_digest nettle_ocb_aes128_digest
0060 #define ocb_aes128_encrypt_message nettle_ocb_aes128_encrypt_message
0061 #define ocb_aes128_decrypt_message nettle_ocb_aes128_decrypt_message
0062 
0063 #define OCB_BLOCK_SIZE 16
0064 #define OCB_DIGEST_SIZE 16
0065 #define OCB_MAX_NONCE_SIZE 15
0066 
0067 struct ocb_key {
0068   
0069   union nettle_block16 L[4];
0070 };
0071 
0072 struct ocb_ctx {
0073   
0074   union nettle_block16 initial;
0075   
0076   union nettle_block16 offset;
0077   
0078   union nettle_block16 sum;
0079   
0080   union nettle_block16 checksum;
0081   
0082   size_t data_count;
0083   size_t message_count;
0084 };
0085 
0086 void
0087 ocb_set_key (struct ocb_key *key, const void *cipher, nettle_cipher_func *f);
0088 
0089 void
0090 ocb_set_nonce (struct ocb_ctx *ctx,
0091            const void *cipher, nettle_cipher_func *f,
0092            size_t tag_length, size_t nonce_length, const uint8_t *nonce);
0093 
0094 void
0095 ocb_update (struct ocb_ctx *ctx, const struct ocb_key *key,
0096         const void *cipher, nettle_cipher_func *f,
0097         size_t length, const uint8_t *data);
0098 
0099 void
0100 ocb_encrypt (struct ocb_ctx *ctx, const struct ocb_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 ocb_decrypt (struct ocb_ctx *ctx, const struct ocb_key *key,
0106          const void *encrypt_ctx, nettle_cipher_func *encrypt,
0107          const void *decrypt_ctx, nettle_cipher_func *decrypt,
0108          size_t length, uint8_t *dst, const uint8_t *src);
0109 
0110 void
0111 ocb_digest (const struct ocb_ctx *ctx, const struct ocb_key *key,
0112         const void *cipher, nettle_cipher_func *f,
0113         size_t length, uint8_t *digest);
0114 
0115 
0116 void
0117 ocb_encrypt_message (const struct ocb_key *ocb_key,
0118              const void *cipher, nettle_cipher_func *f,
0119              size_t nlength, const uint8_t *nonce,
0120              size_t alength, const uint8_t *adata,
0121              size_t tlength,
0122              size_t clength, uint8_t *dst, const uint8_t *src);
0123 
0124 int
0125 ocb_decrypt_message (const struct ocb_key *ocb_key,
0126              const void *encrypt_ctx, nettle_cipher_func *encrypt,
0127              const void *decrypt_ctx, nettle_cipher_func *decrypt,
0128              size_t nlength, const uint8_t *nonce,
0129              size_t alength, const uint8_t *adata,
0130              size_t tlength,
0131              size_t mlength, uint8_t *dst, const uint8_t *src);
0132 
0133 
0134 
0135 
0136 struct ocb_aes128_encrypt_key
0137 {
0138   struct ocb_key ocb;
0139   struct aes128_ctx encrypt;
0140 };
0141 
0142 void
0143 ocb_aes128_set_encrypt_key (struct ocb_aes128_encrypt_key *ocb, const uint8_t *key);
0144 
0145 void
0146 ocb_aes128_set_decrypt_key (struct ocb_aes128_encrypt_key *ocb, struct aes128_ctx *decrypt,
0147                 const uint8_t *key);
0148 
0149 void
0150 ocb_aes128_set_nonce (struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
0151               size_t tag_length, size_t nonce_length, const uint8_t *nonce);
0152 
0153 void
0154 ocb_aes128_update (struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
0155            size_t length, const uint8_t *data);
0156 
0157 void
0158 ocb_aes128_encrypt(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
0159            size_t length, uint8_t *dst, const uint8_t *src);
0160 
0161 void
0162 ocb_aes128_decrypt(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
0163            const struct aes128_ctx *decrypt,
0164            size_t length, uint8_t *dst, const uint8_t *src);
0165 
0166 void
0167 ocb_aes128_digest(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
0168           size_t length, uint8_t *digest);
0169 
0170 void
0171 ocb_aes128_encrypt_message (const struct ocb_aes128_encrypt_key *key,
0172                 size_t nlength, const uint8_t *nonce,
0173                 size_t alength, const uint8_t *adata,
0174                 size_t tlength,
0175                 size_t clength, uint8_t *dst, const uint8_t *src);
0176 
0177 int
0178 ocb_aes128_decrypt_message (const struct ocb_aes128_encrypt_key *key,
0179                 const struct aes128_ctx *decrypt,
0180                 size_t nlength, const uint8_t *nonce,
0181                 size_t alength, const uint8_t *adata,
0182                 size_t tlength,
0183                 size_t mlength, uint8_t *dst, const uint8_t *src);
0184 
0185 #ifdef __cplusplus
0186 }
0187 #endif
0188 
0189 #endif