* This file is part of the openHiTLS project.
*
* openHiTLS is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef CRYPT_MODES_H
#define CRYPT_MODES_H
#include "hitls_build.h"
#ifdef HITLS_CRYPTO_MODES
#include <stdint.h>
#include "crypt_local_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MODES_MAX_IV_LENGTH 24
#define MODES_MAX_BUF_LENGTH 24
#define MODES_IV_LENGTH 16
#define EAL_MAX_BLOCK_LENGTH 32
typedef struct {
void *ciphCtx;
const EAL_SymMethod *ciphMeth;
uint8_t iv[MODES_MAX_IV_LENGTH];
uint8_t buf[MODES_MAX_BUF_LENGTH];
uint8_t blockSize;
uint8_t offset;
uint8_t flag3Iv;
uint32_t ivIndex;
} MODES_CipherCommonCtx;
struct ModesCipherCtx {
MODES_CipherCommonCtx commonCtx;
int32_t algId;
uint8_t data[EAL_MAX_BLOCK_LENGTH];
uint8_t dataLen;
CRYPT_PaddingType pad;
bool enc;
};
typedef struct ModesCipherCtx MODES_CipherCtx;
typedef struct {
const uint8_t *in;
uint8_t *out;
const uint8_t *ctr;
uint8_t *tag;
} XorCryptData;
void MODES_Clean(MODES_CipherCommonCtx *ctx);
int32_t MODES_SetIv(MODES_CipherCommonCtx *ctx, const uint8_t *val, uint32_t len);
int32_t MODES_GetIv(MODES_CipherCommonCtx *ctx, uint8_t *val, uint32_t len);
MODES_CipherCtx *MODES_CipherNewCtx(int32_t algId);
MODES_CipherCtx *MODES_CipherNewCtxEx(void *libCtx, int32_t algId);
MODES_CipherCtx *MODES_CipherDupCtx(const MODES_CipherCtx *modeCtx);
int32_t MODES_CipherFinalComplete(void *modeCtx, uint8_t *out, uint32_t *outLen);
int32_t MODES_CipherDeInitCtx(MODES_CipherCtx *modeCtx);
void MODES_CipherFreeCtx(MODES_CipherCtx *modeCtx);
#ifdef __cplusplus
}
#endif
#endif
#endif