ascon.h (3634B)
1 /* ascon.h 2 * 3 * Copyright (C) 2006-2025 wolfSSL Inc. 4 * 5 * This file is part of wolfSSL. 6 * 7 * wolfSSL is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * wolfSSL is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 */ 21 22 #ifndef WOLF_CRYPT_ASCON_H 23 #define WOLF_CRYPT_ASCON_H 24 25 #ifdef HAVE_ASCON 26 27 #include <wolfssl/wolfcrypt/types.h> 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #define ASCON_HASH256_SZ 32 34 35 #define ASCON_AEAD128_KEY_SZ 16 36 #define ASCON_AEAD128_NONCE_SZ 16 37 #define ASCON_AEAD128_TAG_SZ 16 38 39 typedef union AsconState { 40 #ifdef WORD64_AVAILABLE 41 word64 s64[5]; 42 #endif 43 word32 s32[10]; 44 word16 s16[20]; 45 byte s8[40]; 46 } AsconState; 47 48 typedef struct wc_AsconHash256 { 49 AsconState state; 50 byte lastBlkSz; 51 } wc_AsconHash256; 52 53 enum { 54 ASCON_AEAD128_NOTSET = 0, 55 ASCON_AEAD128_ENCRYPT = 1, 56 ASCON_AEAD128_DECRYPT = 2 57 }; 58 59 typedef struct wc_AsconAEAD128 { 60 /* needed throughout both encrypt and decrypt */ 61 #ifdef WORD64_AVAILABLE 62 word64 key[ASCON_AEAD128_KEY_SZ/sizeof(word64)]; 63 #endif 64 AsconState state; 65 byte lastBlkSz; 66 byte keySet:1; /* has the key been processed */ 67 byte nonceSet:1; /* has the nonce been processed */ 68 byte adSet:1; /* has the associated data been processed */ 69 byte op:2; /* 0 for not set, 1 for encrypt, 2 for decrypt */ 70 } wc_AsconAEAD128; 71 72 /* AsconHash API */ 73 74 WOLFSSL_API wc_AsconHash256* wc_AsconHash256_New(void); 75 WOLFSSL_API void wc_AsconHash256_Free(wc_AsconHash256* a); 76 WOLFSSL_API int wc_AsconHash256_Init(wc_AsconHash256* a); 77 WOLFSSL_API void wc_AsconHash256_Clear(wc_AsconHash256* a); 78 WOLFSSL_API int wc_AsconHash256_Update(wc_AsconHash256* a, const byte* data, 79 word32 dataSz); 80 WOLFSSL_API int wc_AsconHash256_Final(wc_AsconHash256* a, byte* hash); 81 82 WOLFSSL_API wc_AsconAEAD128* wc_AsconAEAD128_New(void); 83 WOLFSSL_API void wc_AsconAEAD128_Free(wc_AsconAEAD128* a); 84 WOLFSSL_API int wc_AsconAEAD128_Init(wc_AsconAEAD128* a); 85 WOLFSSL_API void wc_AsconAEAD128_Clear(wc_AsconAEAD128* a); 86 87 /* AsconAEAD API */ 88 89 WOLFSSL_API int wc_AsconAEAD128_SetKey(wc_AsconAEAD128* a, const byte* key); 90 WOLFSSL_API int wc_AsconAEAD128_SetNonce(wc_AsconAEAD128* a, const byte* nonce); 91 WOLFSSL_API int wc_AsconAEAD128_SetAD(wc_AsconAEAD128* a, const byte* ad, 92 word32 adSz); 93 94 WOLFSSL_API int wc_AsconAEAD128_EncryptUpdate(wc_AsconAEAD128* a, byte* out, 95 const byte* in, word32 inSz); 96 WOLFSSL_API int wc_AsconAEAD128_EncryptFinal(wc_AsconAEAD128* a, byte* tag); 97 98 WOLFSSL_API int wc_AsconAEAD128_DecryptUpdate(wc_AsconAEAD128* a, byte* out, 99 const byte* in, word32 inSz); 100 WOLFSSL_API int wc_AsconAEAD128_DecryptFinal(wc_AsconAEAD128* a, 101 const byte* tag); 102 103 #ifdef __cplusplus 104 } /* extern "C" */ 105 #endif 106 107 #endif /* HAVE_ASCON */ 108 109 #endif /* WOLF_CRYPT_ASCON_H */