| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767 |
- /* Copyright 2018 Canaan Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef _DRIVER_AES_H
- #define _DRIVER_AES_H
- #include <stdint.h>
- #include <stdlib.h>
- #include "dmac.h"
- #include "platform.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef enum _aes_cipher_mode
- {
- AES_ECB = 0,
- AES_CBC = 1,
- AES_GCM = 2,
- AES_CIPHER_MAX,
- } aes_cipher_mode_t;
- typedef enum _aes_kmode
- {
- AES_128 = 16,
- AES_192 = 24,
- AES_256 = 32,
- } aes_kmode_t;
- typedef enum _aes_iv_len
- {
- IV_LEN_96 = 12,
- IV_LEN_128 = 16,
- } aes_iv_len_t;
- typedef enum _aes_encrypt_sel
- {
- AES_HARD_ENCRYPTION = 0,
- AES_HARD_DECRYPTION = 1,
- } aes_encrypt_sel_t;
- typedef struct _aes_mode_ctl
- {
- /* [2:0]:000:ecb; 001:cbc,010:gcm */
- uint32_t cipher_mode : 3;
- /* [4:3]:00:aes-128; 01:aes-192; 10:aes-256;11:reserved*/
- uint32_t kmode : 2;
- /* [6:5]:input key order 1:little endian; 0: big endian */
- uint32_t key_order : 2;
- /* [8:7]:input data order 1:little endian; 0: big endian */
- uint32_t input_order : 2;
- /* [10:9]:output data order 1:little endian; 0: big endian */
- uint32_t output_order : 2;
- uint32_t reserved : 21;
- } __attribute__((packed, aligned(4))) aes_mode_ctl_t;
- /**
- * @brief AES
- */
- typedef struct _aes
- {
- /* (0x00) customer key.1st~4th byte key */
- uint32_t aes_key[4];
- /* (0x10) 0: encryption; 1: decryption */
- uint32_t encrypt_sel;
- /* (0x14) aes mode reg */
- aes_mode_ctl_t mode_ctl;
- /* (0x18) Initialisation Vector. GCM support 96bit. CBC support 128bit */
- uint32_t aes_iv[4];
- /* (0x28) input data endian;1:little endian; 0:big endian */
- uint32_t aes_endian;
- /* (0x2c) calculate status. 1:finish; 0:not finish */
- uint32_t aes_finish;
- /* (0x30) aes out data to dma 0:cpu 1:dma */
- uint32_t dma_sel;
- /* (0x34) gcm Additional authenticated data number */
- uint32_t gb_aad_num;
- uint32_t reserved;
- /* (0x3c) aes plantext/ciphter text input data number */
- uint32_t gb_pc_num;
- /* (0x40) aes plantext/ciphter text input data */
- uint32_t aes_text_data;
- /* (0x44) Additional authenticated data */
- uint32_t aes_aad_data;
- /**
- * (0x48) [1:0],b'00:check not finish; b'01:check fail; b'10:check success;
- * b'11:reversed
- */
- uint32_t tag_chk;
- /* (0x4c) data can input flag. 1: data can input; 0 : data cannot input */
- uint32_t data_in_flag;
- /* (0x50) gcm input tag for compare with the calculate tag */
- uint32_t gcm_in_tag[4];
- /* (0x60) aes plantext/ciphter text output data */
- uint32_t aes_out_data;
- /* (0x64) aes module enable */
- uint32_t gb_aes_en;
- /* (0x68) data can output flag 1: data ready 0: data not ready */
- uint32_t data_out_flag;
- /* (0x6c) allow tag input when use gcm */
- uint32_t tag_in_flag;
- /* (0x70) clear tag_chk */
- uint32_t tag_clear;
- uint32_t gcm_out_tag[4];
- /* (0x84) customer key for aes-192 aes-256.5th~8th byte key */
- uint32_t aes_key_ext[4];
- } __attribute__((packed, aligned(4))) aes_t;
- typedef struct _gcm_context
- {
- /* The buffer holding the encryption or decryption key. */
- uint8_t *input_key;
- /* The initialization vector. must be 96 bit */
- uint8_t *iv;
- /* The buffer holding the Additional authenticated data. or NULL */
- uint8_t *gcm_aad;
- /* The length of the Additional authenticated data. or 0L */
- size_t gcm_aad_len;
- } gcm_context_t;
- typedef struct _cbc_context
- {
- /* The buffer holding the encryption or decryption key. */
- uint8_t *input_key;
- /* The initialization vector. must be 128 bit */
- uint8_t *iv;
- } cbc_context_t;
- /**
- * @brief AES-ECB-128 decryption
- *
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb128_hard_decrypt(uint8_t *input_key, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-ECB-128 encryption
- *
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb128_hard_encrypt(uint8_t *input_key, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-ECB-192 decryption
- *
- * @param[in] input_key The decryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb192_hard_decrypt(uint8_t *input_key, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-ECB-192 encryption
- *
- * @param[in] input_key The encryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb192_hard_encrypt(uint8_t *input_key, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-ECB-256 decryption
- *
- * @param[in] input_key The decryption key. must be 32bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb256_hard_decrypt(uint8_t *input_key, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-ECB-256 encryption
- *
- * @param[in] input_key The encryption key. must be 32bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb256_hard_encrypt(uint8_t *input_key, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-CBC-128 decryption
- *
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc128_hard_decrypt(cbc_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-CBC-128 encryption
- *
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc128_hard_encrypt(cbc_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-CBC-192 decryption
- *
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc192_hard_decrypt(cbc_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-CBC-192 encryption
- *
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc192_hard_encrypt(cbc_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-CBC-256 decryption
- *
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 32bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc256_hard_decrypt(cbc_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-CBC-256 encryption
- *
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 32bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc256_hard_encrypt(cbc_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data);
- /**
- * @brief AES-GCM-128 decryption
- *
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm128_hard_decrypt(gcm_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data, uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-128 encryption
- *
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm128_hard_encrypt(gcm_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data, uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-192 decryption
- *
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm192_hard_decrypt(gcm_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data, uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-192 encryption
- *
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm192_hard_encrypt(gcm_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data, uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-256 decryption
- *
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 32bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm256_hard_decrypt(gcm_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data, uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-256 encryption
- *
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 32bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm256_hard_encrypt(gcm_context_t *context, uint8_t *input_data, size_t input_len, uint8_t *output_data, uint8_t *gcm_tag);
- /**
- * @brief AES-ECB-128 decryption by dma
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb128_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- uint8_t *input_key,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-ECB-128 encryption by dma
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb128_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- uint8_t *input_key,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-ECB-192 decryption by dma
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb192_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- uint8_t *input_key,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-ECB-192 encryption by dma
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb192_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- uint8_t *input_key,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-ECB-256 decryption by dma
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb256_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- uint8_t *input_key,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-ECB-256 encryption by dma
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_ecb256_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- uint8_t *input_key,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-CBC-128 decryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc128_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- cbc_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-CBC-128 encryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc128_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- cbc_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-CBC-192 decryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc192_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- cbc_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-CBC-192 encryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc192_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- cbc_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-CBC-256 decryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc256_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- cbc_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-CBC-256 encryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The cbc context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 24bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * The buffer size must be larger than the size after padding by 16 byte multiples.
- */
- void aes_cbc256_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- cbc_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data);
- /**
- * @brief AES-GCM-128 decryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes. Must be 4 byte multiples.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm128_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- gcm_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data,
- uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-128 encryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes. Must be 4 byte multiples.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm128_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- gcm_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data,
- uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-192 decryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes. Must be 4 byte multiples.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm192_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- gcm_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data,
- uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-192 encryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes. Must be 4 byte multiples.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm192_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- gcm_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data,
- uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-256 decryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The decryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes. Must be 4 byte multiples.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm256_hard_decrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- gcm_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data,
- uint8_t *gcm_tag);
- /**
- * @brief AES-GCM-256 encryption
- *
- * @param[in] dma_receive_channel_num Dmac receive channel number.
- * @param[in] context The gcm context to use for encryption or decryption.
- * @param[in] input_key The encryption key. must be 16bytes.
- * @param[in] input_data The buffer holding the input data.
- * @param[in] input_len The length of a data unit in bytes. Must be 4 byte multiples.
- * This can be any length between 16 bytes and 2^31 bytes inclusive
- * (between 1 and 2^27 block cipher blocks).
- * @param[out] output_data The buffer holding the output data.
- * @param[out] gcm_tag The buffer for holding the tag.The length of the tag must be 4 bytes.
- */
- void aes_gcm256_hard_encrypt_dma(dmac_channel_number_t dma_receive_channel_num,
- gcm_context_t *context,
- uint8_t *input_data,
- size_t input_len,
- uint8_t *output_data,
- uint8_t *gcm_tag);
- /**
- * @brief This function initializes the AES hard module.
- *
- * @param[in] input_key The buffer holding the encryption or decryption key.
- * @param[in] input_key_len The length of the input_key.must be 16bytes || 24bytes || 32bytes.
- * @param[in] iv The initialization vector.
- * @param[in] iv_len The length of the iv.GCM must be 12bytes. CBC must be 16bytes. ECB set 0L.
- * @param[in] gcm_aad The buffer holding the Additional authenticated data. or NULL
- * @param[in] cipher_mode Cipher Modes.must be AES_CBC || AES_ECB || AES_GCM.
- * Other cipher modes, please look forward to the next generation of kendryte.
- * @param[in] encrypt_sel The operation to perform:encryption or decryption.
- * @param[in] gcm_aad_len The length of the gcm_aad.
- * @param[in] input_data_len The length of the input_data.
- */
- void aes_init(uint8_t *input_key, size_t input_key_len, uint8_t *iv, size_t iv_len, uint8_t *gcm_aad,
- aes_cipher_mode_t cipher_mode, aes_encrypt_sel_t encrypt_sel, size_t gcm_aad_len, size_t input_data_len);
- /**
- * @brief This function feeds an input buffer into an encryption or decryption operation.
- *
- * @param[in] input_data The buffer holding the input data.
- * @param[out] output_data The buffer holding the output data.
- * @param[in] input_data_len The length of the input_data.
- * @param[in] cipher_mode Cipher Modes.must be AES_CBC || AES_ECB || AES_GCM.
- * Other cipher modes, please look forward to the next generation of kendryte.
- */
- void aes_process(uint8_t *input_data, uint8_t *output_data, size_t input_data_len, aes_cipher_mode_t cipher_mode);
- /**
- * @brief This function get the gcm tag to verify.
- *
- * @param[out] gcm_tag The buffer holding the gcm tag.The length of the tag must be 16bytes.
- */
- void gcm_get_tag(uint8_t *gcm_tag);
- #ifdef __cplusplus
- }
- #endif
- #endif /* _DRIVER_AES_H */
|