1 /* 2 * Copyright (c) 2023 Eriptic Technologies 3 * 4 * SPDX-License-Identifier: Apache-2.0 or MIT 5 */ 6 7 #ifndef BUFFER_SIZES_H 8 #define BUFFER_SIZES_H 9 10 #ifndef EAD_SIZE 11 #define EAD_SIZE 0 12 #endif 13 14 #ifndef C_I_SIZE 15 #define C_I_SIZE 10 16 #endif 17 18 #ifndef C_R_SIZE 19 #define C_R_SIZE 10 20 #endif 21 22 #ifndef ID_CRED_I_SIZE 23 #define ID_CRED_I_SIZE 400 24 #endif 25 26 #ifndef ID_CRED_R_SIZE 27 #define ID_CRED_R_SIZE 400 28 #endif 29 30 #ifndef CRED_I_SIZE 31 #define CRED_I_SIZE 400 32 #endif 33 34 #ifndef CRED_R_SIZE 35 #define CRED_R_SIZE 400 36 #endif 37 38 #ifndef SUITES_I_SIZE 39 #define SUITES_I_SIZE 6 40 #endif 41 42 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 43 44 #define BSTR_ENCODING_OVERHEAD(x) \ 45 ((x) <= 5) ? 1 : ((x) <= UINT8_MAX) ? 2 : ((x) <= UINT16_MAX) ? 3 : 5 46 47 #define P_256_PRIV_KEY_SIZE 32 48 #define P_256_PUB_KEY_COMPRESSED_SIZE 33 49 #define P_256_PUB_KEY_UNCOMPRESSED_SIZE 65 50 #define P_256_PUB_KEY_X_CORD_SIZE 32 51 #define PK_SIZE P_256_PUB_KEY_UNCOMPRESSED_SIZE 52 #define G_Y_SIZE P_256_PUB_KEY_X_CORD_SIZE 53 #define G_X_SIZE P_256_PUB_KEY_X_CORD_SIZE 54 #define G_R_SIZE P_256_PUB_KEY_UNCOMPRESSED_SIZE 55 #define G_I_SIZE P_256_PUB_KEY_UNCOMPRESSED_SIZE 56 #define SIGNATURE_SIZE 64 57 #define ECDH_SECRET_SIZE 32 58 #define PRK_SIZE 32 59 #define HASH_SIZE 32 60 #define AEAD_IV_SIZE 13 61 #define MAC_SIZE 16 62 #define MAC23_SIZE 32 63 #define AAD_SIZE 45 64 #define KID_SIZE 8 65 #define SIG_OR_MAC_SIZE 64 66 #define ENCODING_OVERHEAD 10 67 #define COSE_SIGN1_STR_LEN 10 /*the length of the string "COSE_Sign1"*/ 68 #define SIG_OR_MAC_SIZE_ENCODING_OVERHEAD 2 69 #define PLAINTEXT3_SIZE_ENCODING_OVERHEAD 3 70 71 #define PLAINTEXT2_SIZE \ 72 (ID_CRED_R_SIZE + SIG_OR_MAC_SIZE + \ 73 SIG_OR_MAC_SIZE_ENCODING_OVERHEAD + EAD_SIZE) 74 #define CIPHERTEXT2_SIZE PLAINTEXT2_SIZE 75 76 #define PLAINTEXT3_SIZE \ 77 (ID_CRED_I_SIZE + SIG_OR_MAC_SIZE + \ 78 SIG_OR_MAC_SIZE_ENCODING_OVERHEAD + EAD_SIZE) 79 #define CIPHERTEXT3_SIZE \ 80 (PLAINTEXT3_SIZE + MAC_SIZE + PLAINTEXT3_SIZE_ENCODING_OVERHEAD) 81 82 #define PLAINTEXT4_SIZE EAD_SIZE 83 #define CIPHERTEXT4_SIZE (PLAINTEXT4_SIZE + ENCODING_OVERHEAD) 84 85 #define MSG_1_SIZE (1 + SUITES_I_SIZE + G_X_SIZE + C_I_SIZE + EAD_SIZE) 86 #define MSG_2_SIZE (G_Y_SIZE + CIPHERTEXT2_SIZE + C_R_SIZE + ENCODING_OVERHEAD) 87 #define MSG_3_SIZE CIPHERTEXT3_SIZE 88 #define MSG_4_SIZE CIPHERTEXT4_SIZE 89 90 #define MSG12_MAX MAX(MSG_1_SIZE, MSG_2_SIZE) 91 #define MSG34_MAX MAX(MSG_3_SIZE, MSG_4_SIZE) 92 #define MSG_MAX_SIZE MAX(MSG12_MAX, MSG34_MAX) 93 #define PLAINTEXT23_MAX_SIZE MAX(PLAINTEXT2_SIZE, PLAINTEXT3_SIZE) 94 #define CRED_MAX_SIZE MAX(CRED_R_SIZE, CRED_I_SIZE) 95 #define ID_CRED_MAX_SIZE MAX(ID_CRED_R_SIZE, ID_CRED_I_SIZE) 96 97 #define SIG_STRUCT_SIZE \ 98 ((2 + HASH_SIZE) + COSE_SIGN1_STR_LEN + ID_CRED_MAX_SIZE + \ 99 CRED_MAX_SIZE + EAD_SIZE + MAC23_SIZE + ENCODING_OVERHEAD) 100 101 #define CONTEXT_MAC_SIZE \ 102 (HASH_SIZE + ID_CRED_MAX_SIZE + CRED_MAX_SIZE + EAD_SIZE + \ 103 ENCODING_OVERHEAD) 104 #define INFO_MAX_SIZE CONTEXT_MAC_SIZE + ENCODING_OVERHEAD 105 106 #define TH34_INPUT_SIZE (HASH_SIZE + PLAINTEXT23_MAX_SIZE + CRED_MAX_SIZE + 2) 107 #define TH2_DEFAULT_SIZE (G_Y_SIZE + C_R_SIZE + HASH_SIZE + ENCODING_OVERHEAD) 108 109 #endif 110