Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esp32c3: aes hmac-sha1 hmac-sha256 stm32f0l0g0 stm32l1 : aes sam34: aes lpc43: aes Signed-off-by: anjiahao <anjiahao@xiaomi.com>
- Loading branch information
Showing
19 changed files
with
1,437 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/lpc43xx/lpc43_crypto.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you 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. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <errno.h> | ||
#include <stdint.h> | ||
|
||
#include <crypto/cryptodev.h> | ||
#include <crypto/xform.h> | ||
#include <nuttx/crypto/crypto.h> | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
static uint32_t g_lpc43_sesnum; | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: authcompute | ||
* | ||
* Description: | ||
* Calculate the hash. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: lpc43_newsession | ||
* | ||
* Description: | ||
* create new session for crypto. | ||
* | ||
****************************************************************************/ | ||
|
||
static int lpc43_newsession(uint32_t *sid, struct cryptoini *cri) | ||
{ | ||
if (sid == NULL || cri == NULL || cri->cri_alg != CRYPTO_AES_CBC) | ||
{ | ||
return -EINVAL; | ||
} | ||
|
||
sid = g_lpc43_sesnum++; | ||
return OK; | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: lpc43_freesession | ||
* | ||
* Description: | ||
* free session. | ||
* | ||
****************************************************************************/ | ||
|
||
static int lpc43_freesession(uint64_t tid) | ||
{ | ||
return 0; | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: lpc43_process | ||
* | ||
* Description: | ||
* process session to use hardware algorithm. | ||
* | ||
****************************************************************************/ | ||
|
||
static int lpc43_process(struct cryptop *crp) | ||
{ | ||
struct cryptodesc *crd; | ||
|
||
for (crd = crp->crp_desc; crd; crd = crd->crd_next) | ||
{ | ||
switch (crd->crd_alg) | ||
{ | ||
case CRYPTO_AES_CBC: | ||
return aes_cypher(crp->crp_dst, crp->crp_buf, crd->crd_len, | ||
crd->crd_iv, crd->crd_key, 16, | ||
AES_MODE_CBC, crd->crd_flags & CRD_F_ENCRYPT); | ||
default: | ||
return -EINVAL; | ||
} | ||
} | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: hwcr_init | ||
* | ||
* Description: | ||
* register the hardware crypto driver. | ||
* | ||
****************************************************************************/ | ||
|
||
void hwcr_init(void) | ||
{ | ||
int hwcr_id; | ||
int algs[CRYPTO_ALGORITHM_MAX + 1]; | ||
|
||
hwcr_id = crypto_get_driverid(0); | ||
DEBUGASSERT(hwcr_id >= 0); | ||
|
||
memset(algs, 0, sizeof(algs)); | ||
|
||
algs[CRYPTO_AES_CBC] = CRYPTO_ALG_FLAG_SUPPORTED; | ||
|
||
crypto_register(hwcr_id, algs, lpc43_newsession, | ||
lpc43_freesession, lpc43_process); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/sam34/sam_crypto.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you 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. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <errno.h> | ||
#include <stdint.h> | ||
|
||
#include <crypto/cryptodev.h> | ||
#include <crypto/xform.h> | ||
#include <nuttx/crypto/crypto.h> | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
FAR static uint32_t g_sam_sesnum = 0; | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: authcompute | ||
* | ||
* Description: | ||
* Calculate the hash. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: sam_newsession | ||
* | ||
* Description: | ||
* create new session for crypto. | ||
* | ||
****************************************************************************/ | ||
|
||
static int sam_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) | ||
{ | ||
if (sid == NULL || cri == NULL) | ||
{ | ||
return -EINVAL; | ||
} | ||
|
||
switch (cri->cri_alg) | ||
{ | ||
case CRYPTO_AES_CBC: | ||
*sid = g_sam_sesnum++; | ||
break; | ||
case CRYPTO_AES_CTR: | ||
if ((cri->cri_klen / 8 - 4) != 16) | ||
{ | ||
/* sam aes-ctr key bits just support 128 */ | ||
|
||
return -EINVAL; | ||
} | ||
|
||
*sid = g_sam_sesnum++; | ||
break; | ||
default : | ||
return -EINVAL; | ||
} | ||
|
||
return OK; | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: sam_freesession | ||
* | ||
* Description: | ||
* free session. | ||
* | ||
****************************************************************************/ | ||
|
||
static int sam_freesession(uint64_t tid) | ||
{ | ||
return 0; | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: sam_process | ||
* | ||
* Description: | ||
* process session to use hardware algorithm. | ||
* | ||
****************************************************************************/ | ||
|
||
static int sam_process(struct cryptop *crp) | ||
{ | ||
struct cryptodesc *crd; | ||
uint8_t iv[AESCTR_BLOCKSIZE]; | ||
|
||
for (crd = crp->crp_desc; crd; crd = crd->crd_next) | ||
{ | ||
switch (crd->crd_alg) | ||
{ | ||
case CRYPTO_AES_CBC: | ||
return aes_cypher(crp->crp_dst, crp->crp_buf, crd->crd_len, | ||
crd->crd_iv, crd->crd_key, 16, | ||
AES_MODE_CBC, crd->crd_flags & CRD_F_ENCRYPT); | ||
case CRYPTO_AES_CTR: | ||
|
||
memcpy(iv, crd->crd_key + crd->crd_klen / 8 - AESCTR_NONCESIZE, | ||
AESCTR_NONCESIZE); | ||
memcpy(iv + AESCTR_NONCESIZE, crd->crd_iv, AESCTR_IVSIZE); | ||
memset(iv + AESCTR_NONCESIZE + AESCTR_IVSIZE , 0, 4); | ||
|
||
return aes_cypher(crp->crp_dst, crp->crp_buf, crd->crd_len, | ||
iv, crd->crd_key, crd->crd_klen / 8 - 4, | ||
AES_MODE_CTR, crd->crd_flags & CRD_F_ENCRYPT); | ||
default: | ||
return -EINVAL; | ||
} | ||
} | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: hwcr_init | ||
* | ||
* Description: | ||
* register the hardware crypto driver. | ||
* | ||
****************************************************************************/ | ||
|
||
void hwcr_init(void) | ||
{ | ||
int hwcr_id; | ||
int algs[CRYPTO_ALGORITHM_MAX + 1]; | ||
|
||
hwcr_id = crypto_get_driverid(0); | ||
DEBUGASSERT(hwcr_id >= 0); | ||
|
||
memset(algs, 0, sizeof(algs)); | ||
|
||
algs[CRYPTO_AES_CBC] = CRYPTO_ALG_FLAG_SUPPORTED; | ||
algs[CRYPTO_AES_CTR] = CRYPTO_ALG_FLAG_SUPPORTED; | ||
|
||
crypto_register(hwcr_id, algs, sam_newsession, | ||
sam_freesession, sam_process); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.