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 BSL_BASE64_INTERNAL_H 17 #define BSL_BASE64_INTERNAL_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_BSL_BASE64 21 22 #include "bsl_base64.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 struct BASE64_ControlBlock { 29 /* size of the unencoded block in the current buffer */ 30 uint32_t num; 31 /* 32 * Size of the block for internal encoding and decoding. 33 * The size of the coding block is set to 48, and the size of the decoding block is set to 64. 34 */ 35 uint32_t length; 36 /* see BSL_BASE64_FLAGS*, for example: BSL_BASE64_FLAGS_NO_NEWLINE, means process without '\n' */ 37 uint32_t flags; 38 uint32_t paddingCnt; 39 /* codec buffer */ 40 uint8_t buf[HITLS_BASE64_CTX_BUF_LENGTH]; 41 }; 42 43 #define BASE64_ENCODE_BYTES 3 // encode 3 bytes at a time 44 #define BASE64_DECODE_BYTES 4 // decode 4 bytes at a time 45 #define BASE64_BLOCK_SIZE 1024 46 #define BASE64_PAD_MAX 2 47 #define BASE64_DECODE_BLOCKSIZE 64 48 #define BASE64_CTX_BUF_SIZE HITLS_BASE64_ENCODE_LENGTH(BASE64_BLOCK_SIZE) + 10 49 #define BSL_BASE64_ENC_ENOUGH_LEN(len) (((len) + 2) / 3 * 4 + 1) 50 #define BSL_BASE64_DEC_ENOUGH_LEN(len) (((len) + 3) / 4 * 3) 51 52 #ifdef __cplusplus 53 } 54 #endif /* __cplusplus */ 55 #endif /* HITLS_BSL_BASE64 */ 56 #endif /* conditional include */