/* sp.c
*
* Copyright (C) 2006-2020 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
/* Implementation by Sean Parkinson. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/cpuid.h>
#ifdef NO_INLINE
#include <wolfssl/wolfcrypt/misc.h>
#else
#define WOLFSSL_MISC_INCLUDED
#include <wolfcrypt/src/misc.c>
#endif
#if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH) || \
defined(WOLFSSL_HAVE_SP_ECC)
#ifdef RSA_LOW_MEM
#ifndef WOLFSSL_SP_SMALL
#define WOLFSSL_SP_SMALL
#endif
#endif
#include <wolfssl/wolfcrypt/sp.h>
#ifdef WOLFSSL_SP_ARM64_ASM
#if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH)
#ifndef WOLFSSL_SP_NO_2048
/* Read big endian unsigned byte array into r.
*
* r A single precision integer.
* size Maximum number of bytes to convert
* a Byte array.
* n Number of bytes in array to read.
*/
static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n)
{
int i, j;
byte* d;
for (i = n - 1,j = 0; i >= 7; i -= 8) {
r[j] = ((sp_digit)a[i - 0] << 0) |
((sp_digit)a[i - 1] << 8) |
((sp_digit)a[i - 2] << 16) |
((sp_digit)a[i - 3] << 24) |
((sp_digit)a[i - 4] << 32) |
((sp_digit)a[i - 5] << 40) |
((sp_digit)a[i - 6] << 48) |
((sp_digit)a[i - 7] << 56);
j++;
}
if (i >= 0) {
r[j] = 0;
d = (byte*)r;
switch (i) {
case 6: d[n - 1 - 6] = a[6]; //fallthrough
case 5: d[n - 1 - 5] = a[5]; //fallthrough
case 4: d[n - 1 - 4] = a[4]; //fallthrough
case 3: d[n - 1 - 3] = a[3]; //fallthrough
case 2: d[n - 1 - 2] = a[2]; //fallthrough
case 1: d[n - 1 - 1] = a[1]; //fallthrough
case 0: d[n - 1 - 0] = a[0]; //fallthrough
}
j++;
}
for (; j < size; j++) {
r[j] = 0;
}
}
/* Convert an mp_int to an array of sp_digit.
*
* r A single precision integer.
* size Maximum number of bytes to convert
* a A multi-precision integer.
*/
static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a)
{
#if DIGIT_BIT == 64
int j;
XMEMCPY(r, a->dp, sizeof(sp_digit) * a->used);
for (j = a->used; j < size; j++) {
r[j] = 0;
}
#elif DIGIT_BIT > 64
int i, j = 0;
word32 s = 0;
r[0] = 0;
for (i = 0; i < a->used && j < size; i++) {
r[j] |= ((sp_digit)a->dp[i] << s);
r[j] &= 0xffffffffffffffffl;
s = 64U - s;
if (j + 1 >= size) {
break;
}
/* lint allow cast of mismatch word32 and mp_digit */
r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
while ((s + 64U) <= (word32)DIGIT_BIT) {
s += 64U;
r[j] &= 0xffffffffffffffffl;
if (j + 1 >= size) {
break;
}
if (s < (word32)DIGIT_BIT) {
/* lint allow cast of mismatch word32 and mp_digit */
r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
}
else {
r[++j] = 0L;
}
}
s = (word32)DIGIT_BIT - s;
}
for (j++; j < size; j++) {
r[j] = 0;
}
#else
int i, j = 0, s = 0;
r[0] = 0;
for (i = 0; i < a->used && j < size; i++) {
r[j] |= ((sp_digit)a->dp[i]) << s;
if (s + DIGIT_BIT >= 64) {
r[j] &= 0xffffffffffffffffl;
if (j + 1 >= size) {
break;
}
s = 64 - s;
if (s == DIGIT_BIT) {
r[++j] = 0;
s = 0;
}
else {
r[++j] = a->dp[i] >> s;
s = DIGIT_BIT - s;
}
}
else {
s += DIGIT_BIT;
}
}
for (j++; j < size; j++) {
r[j] = 0;
}
#endif
}
/* Write r as big endian to byte array.
* Fixed length number of bytes written: 256
*
* r A single precision integer.
* a Byte array.
*/
static void sp_2048_to_bin(sp_digit* r, byte* a)
{
int i, j;
for (i = 31, j = 0; i >= 0; i--) {
a[j++] = r[i] >> 56;
a[j++] = r[i] >> 48;
a[j++] = r[i] >> 40;
a[j++] = r[i] >> 32;
a[j++] = r[i] >> 24;
a[j++] = r[i] >> 16;
a[j++] = r[i] >> 8;
a[j++] = r[i] >> 0;
}
}
#ifndef WOLFSSL_SP_SMALL
/* Multiply a and b into r. (r = a * b)
*
* r A single precision integer.
* a A single precision integer.
* b A single precision integer.
*/
static void sp_2048_mul_8(sp_digit* r, const sp_digit* a, const sp_digit* b)
{
sp_digit tmp[8];
__asm__ __volatile__ (
"ldp x9, x10, [%[a], 0]\n\t"
"ldp x11, x12, [%[a], 16]\n\t"
"ldp x13, x14, [%[a], 32]\n\t"
"ldp x15, x16, [%[a], 48]\n\t"
"ldp x17, x19, [%[b], 0]\n\t"
"ldp x20, x21, [%[b], 16]\n\t"
"ldp x22, x23, [%[b], 32]\n\t"
"ldp x24, x25, [%[b], 48]\n\t"
"# A[0] * B[0]\n\t"
"mul x4, x9, x17\n\t"
"umulh x5, x9, x17\n\t"
"str x4, [%[tmp]]\n\t"
"# A[0] * B[1]\n\t"
"mul x7, x9, x19\n\t"
"umulh x8, x9, x19\n\t"
"adds x5, x5, x7\n\t"
"# A[1] * B[0]\n\t"
"mul x7, x10, x17\n\t"
"adc x6, xzr, x8\n\t"
"umulh x8, x10, x17\n\t"
"adds x5, x5, x7\n\t"
"adcs x6, x6, x8\n\t"
"str x5, [%[tmp], 8]\n\t"
"adc x4, xzr, xzr\n\t"
"# A[0] * B[2]\n\t"
"mul x7, x9, x20\n\t"
"umulh x8, x9, x20\n\t"
"adds x6, x6, x7\n\t"
"# A[1] * B[1]\n\t"
"mul x7, x10, x19\n\t"
"adcs x4, x4, x8\n\t"
"umulh x8, x10, x19\n\t"
"adc x5, xzr, xzr\n\t"
"adds x6, x6, x7\n\t"
"# A[2] * B[0]\n\t"
"mul x7, x11, x17\n\t"
"adcs x4, x4, x8\n\t"
"umulh x8, x11, x17\n\t"
"adc x5, x5, xzr\n\t"
"adds x6, x6, x7\n\t"
"adcs x4, x4, x8\n\t"
"str x6, [%[tmp], 16]\n\t"
"adc x5, x5, xzr\n\t"
"# A[0] * B[3]\n\t"
"mul x7, x9, x21\n\t"
"umulh x8, x9, x21\n\t"
"adds x4, x4, x7\n\t"
"# A[1] * B[2]\n\t"
"mul x7, x10, x20\n\t"
"adcs x5, x5, x8\n\t"
"umulh x8, x10, x20\n\t"
"adc x6, xzr, xzr\n\t"
"adds x4, x4, x7\n\t"
"# A[2] * B[1]\n\t"
"mul x7, x11, x19\n\t"
"adcs x5, x5, x8\n\t"
"umulh x8, x11, x19\n\t"
"adc x6, x6, xzr\n\t"
"adds x4, x4, x7\n\t"
"# A[3] * B[0]\n\t"
"mul x7, x12, x17\n\t"
"adcs x5, x5, x8\n\t"
"umulh x8, x12, x17\n\t"
"adc x6, x6, xzr\n\t"
"adds x4, x4, x7\n\t"
"adcs x5, x5, x8\n\t"
"str x4, [%[tmp], 24]\n\t"
"adc x6, x6, xzr\n\t"
"# A[0] * B[4]\n\t"
"mul x7, x9, x22\n\t"
"umulh x8, x9, x22\n\t"
"adds x5, x5, x7\n\t"
"# A[1] * B[3]\n\t"
"mul x7, x10, x21\n\t"
"adcs x6, x6, x8\n\t"
"umulh x8, x10, x21\n\t"
"adc x4, xzr, xzr\n\t"
"adds x
没有合适的资源?快使用搜索试试~ 我知道了~
FreeRTOS-202107.00.tar.gz
需积分: 9 1 下载量 74 浏览量
2021-10-30
13:17:16
上传
评论 1
收藏 50.45MB GZ 举报
温馨提示
共2000个文件
h:5431个
c:3756个
s:264个
FreeRTOS 202107 发布版本
资源详情
资源评论
资源推荐
收起资源包目录
FreeRTOS-202107.00.tar.gz (2000个子文件)
sp_arm64.c 1.5MB
sp_arm32.c 1.41MB
ssl.c 1.33MB
sp_x86_64.c 1.11MB
internal.c 1013KB
test.c 924KB
sp_cortexm.c 905KB
sp_armthumb.c 899KB
psu_init.c 876KB
psu_init.c 876KB
psu_init_gpl.c 875KB
psu_init_gpl.c 875KB
sp_c32.c 844KB
sp_c64.c 788KB
ps7_init.c 563KB
ps7_init_gpl.c 562KB
ge_operations.c 528KB
asn.c 508KB
ge_448.c 493KB
pkcs7.c 401KB
ecc.c 393KB
tls.c 356KB
stm32h7xx_hal_hrtim.c 315KB
aes.c 290KB
tls13.c 269KB
stm32h7xx_hal_tim.c 227KB
stm32l4xx_hal_tim.c 221KB
stm32h7xx_hal_tim.c 220KB
stm32l4xx_hal_i2c.c 216KB
alt_clock_manager.c 212KB
stm32h7xx_hal_i2c.c 211KB
stm32h7xx_hal_fdcan.c 203KB
evp.c 203KB
stm32l1xx_hal_tim.c 202KB
benchmark.c 195KB
stm32f7xx_hal_tim.c 177KB
sp_dsp32.c 173KB
stm32h7xx_hal_cryp.c 164KB
sniffer.c 163KB
fsdata.c 159KB
fsdata.c 159KB
fsdata.c 159KB
fsdata.c 159KB
stm32h7xx_hal_adc.c 144KB
keys.c 142KB
stm32l4xx_hal_uart.c 140KB
stm32fxxx_eth.c 138KB
stm32h7xx_hal_jpeg.c 138KB
stm32l4xx_hal_spi.c 137KB
stm32h7xx_hal_uart.c 136KB
stm32h7xx_hal_uart.c 135KB
alt_dma.c 135KB
stm32h7xx_hal_dfsdm.c 129KB
stm32l4xx_hal_dfsdm.c 128KB
stm32l4xx_hal_rcc_ex.c 126KB
stm32h7xx_hal_hash.c 126KB
stm32f7xx_hal_i2c.c 126KB
rsa.c 125KB
tfm.c 123KB
stm32h7xx_hal_usart.c 122KB
stm32h7xx_hal_usart.c 122KB
stm32f7xx_hal_cryp.c 120KB
stm32f0xx_tim.c 120KB
stm32h7xx_hal_sd.c 120KB
stm32h7xx_hal_smartcard.c 120KB
stm32h7xx_hal_spi.c 118KB
integer.c 117KB
crypto.c 117KB
em_cmu.c 114KB
em_cmu.c 114KB
stm32h7xx_hal_rcc_ex.c 111KB
stm32l1xx_tim.c 108KB
stm32l1xx_hal_uart.c 108KB
stm32f10x_tim1.c 107KB
stm32f10x_tim1.c 107KB
stm32f10x_tim1.c 107KB
stm32f7xx_hal_sd.c 106KB
trcSnapshotRecorder.c 104KB
stm32f7xx_hal_cryp_ex.c 103KB
mib2.c 103KB
stm32h7xx_hal_ospi.c 103KB
mib2.c 102KB
test_tcp.c 102KB
stm32h7xx_hal_eth.c 101KB
stm32h7xx_hal_irda.c 100KB
stm32h7xx_hal_rcc_ex.c 99KB
stm32h7xx_hal_mmc.c 98KB
posix.c 97KB
stm32l1xx_rtc.c 96KB
stm32h7xx_hal_adc_ex.c 95KB
stm32l4xx_hal_qspi.c 93KB
stm32h7xx_hal_smbus.c 92KB
stm32f10x_tim.c 92KB
stm32f10x_tim.c 92KB
stm32f10x_tim.c 92KB
stm32f10x_tim.c 92KB
stm32l1xx_tim.c 91KB
stm32h7xx_hal_sai.c 90KB
ov5640_config.c 89KB
stm32h7xx_hal_rtc_ex.c 89KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
zhang_gq
- 粉丝: 7
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0