File indexing completed on 2025-01-18 10:02:16
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_UMAC_H_INCLUDED
0035 #define NETTLE_UMAC_H_INCLUDED
0036
0037 #ifdef __cplusplus
0038 extern "C" {
0039 #endif
0040
0041
0042 #define umac32_set_key nettle_umac32_set_key
0043 #define umac64_set_key nettle_umac64_set_key
0044 #define umac96_set_key nettle_umac96_set_key
0045 #define umac128_set_key nettle_umac128_set_key
0046 #define umac32_set_nonce nettle_umac32_set_nonce
0047 #define umac64_set_nonce nettle_umac64_set_nonce
0048 #define umac96_set_nonce nettle_umac96_set_nonce
0049 #define umac128_set_nonce nettle_umac128_set_nonce
0050 #define umac32_update nettle_umac32_update
0051 #define umac64_update nettle_umac64_update
0052 #define umac96_update nettle_umac96_update
0053 #define umac128_update nettle_umac128_update
0054 #define umac32_digest nettle_umac32_digest
0055 #define umac64_digest nettle_umac64_digest
0056 #define umac96_digest nettle_umac96_digest
0057 #define umac128_digest nettle_umac128_digest
0058
0059 #include "nettle-types.h"
0060 #include "aes.h"
0061
0062 #define UMAC_KEY_SIZE AES128_KEY_SIZE
0063 #define UMAC32_DIGEST_SIZE 4
0064 #define UMAC64_DIGEST_SIZE 8
0065 #define UMAC96_DIGEST_SIZE 12
0066 #define UMAC128_DIGEST_SIZE 16
0067 #define UMAC_BLOCK_SIZE 1024
0068 #define UMAC_MIN_NONCE_SIZE 1
0069 #define UMAC_MAX_NONCE_SIZE AES_BLOCK_SIZE
0070
0071 #define UMAC_DATA_SIZE UMAC_BLOCK_SIZE
0072
0073
0074 #define _UMAC_STATE(n) \
0075 uint32_t l1_key[UMAC_BLOCK_SIZE/4 + 4*((n)-1)]; \
0076 \
0077 uint32_t l2_key[6*(n)]; \
0078 uint64_t l3_key1[8*(n)]; \
0079 uint32_t l3_key2[(n)]; \
0080 \
0081 struct aes128_ctx pdf_key; \
0082
0083
0084 \
0085 uint64_t l2_state[3*(n)]; \
0086
0087 \
0088 uint8_t nonce[AES_BLOCK_SIZE]; \
0089 unsigned short nonce_length
0090
0091
0092 #define _UMAC_BUFFER \
0093 unsigned index; \
0094 \
0095 uint64_t count; \
0096 uint8_t block[UMAC_BLOCK_SIZE]
0097
0098 #define _UMAC_NONCE_CACHED 0x80
0099
0100 struct umac32_ctx
0101 {
0102 _UMAC_STATE(1);
0103
0104 unsigned short nonce_low;
0105
0106 uint32_t pad_cache[AES_BLOCK_SIZE / 4];
0107 _UMAC_BUFFER;
0108 };
0109
0110 struct umac64_ctx
0111 {
0112 _UMAC_STATE(2);
0113
0114 unsigned short nonce_low;
0115
0116 uint32_t pad_cache[AES_BLOCK_SIZE/4];
0117 _UMAC_BUFFER;
0118 };
0119
0120 struct umac96_ctx
0121 {
0122 _UMAC_STATE(3);
0123 _UMAC_BUFFER;
0124 };
0125
0126 struct umac128_ctx
0127 {
0128 _UMAC_STATE(4);
0129 _UMAC_BUFFER;
0130 };
0131
0132
0133 void
0134 umac32_set_key (struct umac32_ctx *ctx, const uint8_t *key);
0135 void
0136 umac64_set_key (struct umac64_ctx *ctx, const uint8_t *key);
0137 void
0138 umac96_set_key (struct umac96_ctx *ctx, const uint8_t *key);
0139 void
0140 umac128_set_key (struct umac128_ctx *ctx, const uint8_t *key);
0141
0142
0143 void
0144 umac32_set_nonce (struct umac32_ctx *ctx,
0145 size_t nonce_length, const uint8_t *nonce);
0146 void
0147 umac64_set_nonce (struct umac64_ctx *ctx,
0148 size_t nonce_length, const uint8_t *nonce);
0149 void
0150 umac96_set_nonce (struct umac96_ctx *ctx,
0151 size_t nonce_length, const uint8_t *nonce);
0152 void
0153 umac128_set_nonce (struct umac128_ctx *ctx,
0154 size_t nonce_length, const uint8_t *nonce);
0155
0156 void
0157 umac32_update (struct umac32_ctx *ctx,
0158 size_t length, const uint8_t *data);
0159 void
0160 umac64_update (struct umac64_ctx *ctx,
0161 size_t length, const uint8_t *data);
0162 void
0163 umac96_update (struct umac96_ctx *ctx,
0164 size_t length, const uint8_t *data);
0165 void
0166 umac128_update (struct umac128_ctx *ctx,
0167 size_t length, const uint8_t *data);
0168
0169
0170 void
0171 umac32_digest (struct umac32_ctx *ctx,
0172 size_t length, uint8_t *digest);
0173 void
0174 umac64_digest (struct umac64_ctx *ctx,
0175 size_t length, uint8_t *digest);
0176 void
0177 umac96_digest (struct umac96_ctx *ctx,
0178 size_t length, uint8_t *digest);
0179 void
0180 umac128_digest (struct umac128_ctx *ctx,
0181 size_t length, uint8_t *digest);
0182
0183
0184
0185 #define UMAC_POLY64_BLOCKS 16384
0186
0187 #define UMAC_P64_OFFSET 59
0188 #define UMAC_P64 (- (uint64_t) UMAC_P64_OFFSET)
0189
0190 #define UMAC_P128_OFFSET 159
0191 #define UMAC_P128_HI (~(uint64_t) 0)
0192 #define UMAC_P128_LO (-(uint64_t) UMAC_P128_OFFSET)
0193
0194 #ifdef __cplusplus
0195 }
0196 #endif
0197
0198 #endif