1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 #ifndef PRIVPASS_TOKEN_H 17 #define PRIVPASS_TOKEN_H 18 19 #include <stdint.h> 20 #include "bsl_types.h" 21 #include "bsl_params.h" 22 #include "auth_params.h" 23 #include "auth_privpass_token.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* Constants for Private Pass Token */ 30 #define PRIVPASS_PUBLIC_VERIFY_TOKENTYPE ((uint16_t)0x0002) 31 #define PRIVPASS_TOKEN_NK 256 // RSA-2048 key size in bytes 32 #define PRIVPASS_TOKEN_SHA256_SIZE 32 // SHA256 hash size in bytes 33 #define PRIVPASS_TOKEN_NONCE_LEN 32 // Random nonce length 34 #define PRIVPASS_MAX_ISSUER_NAME_LEN 65535 35 #define PRIVPASS_REDEMPTION_LEN 32 36 #define PRIVPASS_MAX_ORIGIN_INFO_LEN 65535 37 38 // 2(tokenType) + 32(nonce) + 32(challengeDigest) + 32(tokenKeyId) 39 #define HITLS_AUTH_PRIVPASS_TOKEN_INPUT_LEN (2 + 32 + 32 + 32) 40 41 /* Structure for token challenge request */ 42 typedef struct { 43 uint8_t *challengeReq; // Challenge request data 44 uint32_t challengeReqLen; // Length of challenge request 45 } PrivPass_TokenChallengeReq; 46 47 /* Structure for token challenge from server */ 48 typedef struct { 49 uint16_t tokenType; // Token type (e.g., Blind RSA 2048-bit) 50 BSL_Buffer issuerName; // Name of the token issuer 51 BSL_Buffer redemption; // Redemption information 52 BSL_Buffer originInfo; // Origin information 53 } PrivPass_TokenChallenge; 54 55 typedef struct { 56 uint16_t tokenType; 57 uint8_t truncatedTokenKeyId; 58 BSL_Buffer blindedMsg; 59 } PrivPass_TokenRequest; 60 61 typedef struct { 62 uint8_t *blindSig; 63 uint32_t blindSigLen; 64 } PrivPass_TokenPubResponse; 65 66 typedef enum { 67 HITLS_AUTH_PRIVPASS_TOKEN_RESPONSE_PUB = 1, 68 } PrivPass_TokenResponseType; 69 70 typedef struct { 71 int32_t type; 72 union { 73 PrivPass_TokenPubResponse pubResp; 74 } st; 75 } PrivPass_TokenResponse; 76 77 typedef struct { 78 uint16_t tokenType; 79 uint8_t nonce[PRIVPASS_TOKEN_NONCE_LEN]; 80 uint8_t challengeDigest[PRIVPASS_TOKEN_SHA256_SIZE]; 81 uint8_t tokenKeyId[PRIVPASS_TOKEN_SHA256_SIZE]; 82 BSL_Buffer authenticator; 83 } PrivPass_TokenInstance; 84 85 struct PrivPass_Token { 86 int32_t type; 87 union { 88 PrivPass_TokenChallengeReq *tokenChallengeReq; 89 PrivPass_TokenChallenge *tokenChallenge; 90 PrivPass_TokenRequest *tokenRequest; 91 PrivPass_TokenResponse *tokenResponse; 92 PrivPass_TokenInstance *token; 93 } st; 94 }; 95 96 typedef struct { 97 HITLS_AUTH_PrivPassNewPkeyCtx newPkeyCtx; 98 HITLS_AUTH_PrivPassFreePkeyCtx freePkeyCtx; 99 HITLS_AUTH_PrivPassDigest digest; 100 HITLS_AUTH_PrivPassBlind blind; 101 HITLS_AUTH_PrivPassUnblind unBlind; 102 HITLS_AUTH_PrivPassSignData signData; 103 HITLS_AUTH_PrivPassVerify verify; 104 HITLS_AUTH_PrivPassDecodePubKey decodePubKey; 105 HITLS_AUTH_PrivPassDecodePrvKey decodePrvKey; 106 HITLS_AUTH_PrivPassCheckKeyPair checkKeyPair; 107 HITLS_AUTH_PrivPassRandom random; 108 } PrivPassCryptCb; 109 110 /* Main context structure for Private Pass operations */ 111 struct PrivPass_Ctx { 112 void *prvKeyCtx; // Private key context 113 void *pubKeyCtx; // Public key context 114 uint8_t tokenKeyId[PRIVPASS_TOKEN_SHA256_SIZE]; // Token key identifier 115 uint8_t nonce[PRIVPASS_TOKEN_NONCE_LEN]; // Random nonce 116 PrivPassCryptCb method; // Cryptographic callbacks 117 }; 118 119 /** 120 * @brief Get the default cryptographic callback functions. 121 * @retval PrivPassCryptCb structure containing default callbacks. 122 */ 123 PrivPassCryptCb PrivPassCryptPubCb(void); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif // PRIVPASS_TOKEN_H 130