1 /* $NetBSD: gmac.h,v 1.4 2026/07/05 15:33:44 riastradh Exp $ */ 2 /* OpenBSD: gmac.h,v 1.1 2010/09/22 11:54:23 mikeb Exp */ 3 4 /* 5 * Copyright (c) 2010 Mike Belopuhov <mike (at) vantronix.net> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _GMAC_H_ 21 #define _GMAC_H_ 22 23 #include <sys/types.h> 24 25 #include <crypto/aes/aes.h> 26 27 #define GMAC_BLOCK_LEN 16 28 #define GMAC_DIGEST_LEN 16 29 30 #ifdef _LP64 31 #define GMAC_INT uint64_t 32 #define GMAC_INTLEN 8 33 #else 34 #define GMAC_INT uint32_t 35 #define GMAC_INTLEN 4 36 #endif 37 38 typedef struct _GHASH_CTX { 39 GMAC_INT H[GMAC_BLOCK_LEN/GMAC_INTLEN]; /* hash subkey */ 40 GMAC_INT S[GMAC_BLOCK_LEN/GMAC_INTLEN]; /* state */ 41 GMAC_INT Z[GMAC_BLOCK_LEN/GMAC_INTLEN]; /* initial state */ 42 } GHASH_CTX; 43 44 typedef struct _AES_GMAC_CTX { 45 GHASH_CTX ghash; 46 struct aesenc K; 47 uint8_t J[GMAC_BLOCK_LEN]; /* counter block */ 48 int rounds; 49 } AES_GMAC_CTX; 50 51 #include <sys/cdefs.h> 52 53 __BEGIN_DECLS 54 void AES_GMAC_Init(AES_GMAC_CTX *); 55 void AES_GMAC_Setkey(AES_GMAC_CTX *, const uint8_t *, uint16_t); 56 void AES_GMAC_Reinit(AES_GMAC_CTX *, const uint8_t *, uint16_t); 57 int AES_GMAC_Update(AES_GMAC_CTX *, const uint8_t *, uint16_t); 58 void AES_GMAC_Final(uint8_t [GMAC_DIGEST_LEN], AES_GMAC_CTX *); 59 __END_DECLS 60 61 #endif /* _GMAC_H_ */ 62