* 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_CCM_H
#define CRYPT_MODES_CCM_H
#include "hitls_build.h"
#ifdef HITLS_CRYPTO_CCM
#include "crypt_types.h"
#include "crypt_modes.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CCM_BLOCKSIZE 16
#define CCM_MAX_TAGSIZE 16
typedef struct {
void *ciphCtx;
const EAL_SymMethod *ciphMeth;
uint8_t nonce[CCM_BLOCKSIZE];
uint8_t tag[CCM_BLOCKSIZE];
uint8_t last[CCM_BLOCKSIZE];
uint64_t msgLen;
uint8_t lastLen;
uint8_t tagLen;
uint8_t tagInit;
} MODES_CipherCCMCtx;
struct ModesCcmCtx {
int32_t algId;
MODES_CipherCCMCtx ccmCtx;
uint8_t vfyTag[CCM_MAX_TAGSIZE];
uint32_t vfyTagLen;
bool enc;
};
typedef struct ModesCcmCtx MODES_CCM_Ctx;
MODES_CCM_Ctx *MODES_CCM_NewCtx(int32_t algId);
MODES_CCM_Ctx *MODES_CCM_NewCtxEx(void *libCtx, int32_t algId);
int32_t MODES_CCM_InitCtx(MODES_CCM_Ctx *modeCtx, const uint8_t *key, uint32_t keyLen, const uint8_t *iv,
uint32_t ivLen, void *param, bool enc);
int32_t MODES_CCM_Update(MODES_CCM_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
int32_t MODES_CCM_Final(MODES_CCM_Ctx *modeCtx, uint8_t *out, uint32_t *outLen);
int32_t MODES_CCM_DeInitCtx(MODES_CCM_Ctx *modeCtx);
int32_t MODES_CCM_Ctrl(MODES_CCM_Ctx *modeCtx, int32_t opt, void *val, uint32_t len);
void MODES_CCM_FreeCtx(MODES_CCM_Ctx *modeCtx);
int32_t AES_CCM_Update(MODES_CCM_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
int32_t MODES_CCM_UpdateEx(MODES_CCM_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
MODES_CCM_Ctx *MODES_CCM_DupCtx(const MODES_CCM_Ctx *modeCtx);
#ifdef __cplusplus
}
#endif
#endif
#endif