| 1 | /* $NetBSD: gmac.h,v 1.2 2011/06/09 14:47:42 drochner 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@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 <crypto/rijndael/rijndael.h> |
| 24 | |
| 25 | #define GMAC_BLOCK_LEN 16 |
| 26 | #define GMAC_DIGEST_LEN 16 |
| 27 | |
| 28 | #ifdef _LP64 |
| 29 | #define GMAC_INT uint64_t |
| 30 | #define GMAC_INTLEN 8 |
| 31 | #else |
| 32 | #define GMAC_INT uint32_t |
| 33 | #define GMAC_INTLEN 4 |
| 34 | #endif |
| 35 | |
| 36 | typedef struct _GHASH_CTX { |
| 37 | GMAC_INT H[GMAC_BLOCK_LEN/GMAC_INTLEN]; /* hash subkey */ |
| 38 | GMAC_INT S[GMAC_BLOCK_LEN/GMAC_INTLEN]; /* state */ |
| 39 | GMAC_INT Z[GMAC_BLOCK_LEN/GMAC_INTLEN]; /* initial state */ |
| 40 | } GHASH_CTX; |
| 41 | |
| 42 | typedef struct _AES_GMAC_CTX { |
| 43 | GHASH_CTX ghash; |
| 44 | uint32_t K[4*(RIJNDAEL_MAXNR + 1)]; |
| 45 | uint8_t J[GMAC_BLOCK_LEN]; /* counter block */ |
| 46 | int rounds; |
| 47 | } AES_GMAC_CTX; |
| 48 | |
| 49 | #include <sys/cdefs.h> |
| 50 | |
| 51 | __BEGIN_DECLS |
| 52 | void AES_GMAC_Init(AES_GMAC_CTX *); |
| 53 | void AES_GMAC_Setkey(AES_GMAC_CTX *, const uint8_t *, uint16_t); |
| 54 | void AES_GMAC_Reinit(AES_GMAC_CTX *, const uint8_t *, uint16_t); |
| 55 | int AES_GMAC_Update(AES_GMAC_CTX *, const uint8_t *, uint16_t); |
| 56 | void AES_GMAC_Final(uint8_t [GMAC_DIGEST_LEN], AES_GMAC_CTX *); |
| 57 | __END_DECLS |
| 58 | |
| 59 | #endif /* _GMAC_H_ */ |
| 60 | |