/* sp.c
*
* Copyright (C) 2006-2018 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 2 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 <../src/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
#define SP_RSA_PRIVATE_EXP_D
#ifndef WOLFSSL_SP_SMALL
#define WOLFSSL_SP_SMALL
#endif
#endif
#include <wolfssl/wolfcrypt/sp.h>
#ifdef WOLFSSL_SP_X86_64_ASM
#if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH)
#ifndef WOLFSSL_SP_NO_2048
/* Read big endian unsigned byte aray into r.
*
* r A single precision integer.
* a Byte array.
* n Number of bytes in array to read.
*/
static void sp_2048_from_bin(sp_digit* r, int max, const byte* a, int n)
{
int i, j = 0, s = 0;
r[0] = 0;
for (i = n-1; i >= 0; i--) {
r[j] |= ((sp_digit)a[i]) << s;
if (s >= 56) {
r[j] &= 0xffffffffffffffffl;
s = 64 - s;
if (j + 1 >= max)
break;
r[++j] = a[i] >> s;
s = 8 - s;
}
else
s += 8;
}
for (j++; j < max; j++)
r[j] = 0;
}
/* Convert an mp_int to an array of sp_digit.
*
* r A single precision integer.
* a A multi-precision integer.
*/
static void sp_2048_from_mp(sp_digit* r, int max, mp_int* a)
{
#if DIGIT_BIT == 64
int j;
XMEMCPY(r, a->dp, sizeof(sp_digit) * a->used);
for (j = a->used; j < max; j++)
r[j] = 0;
#elif DIGIT_BIT > 64
int i, j = 0, s = 0;
r[0] = 0;
for (i = 0; i < a->used && j < max; i++) {
r[j] |= a->dp[i] << s;
r[j] &= 0xffffffffffffffffl;
s = 64 - s;
if (j + 1 >= max)
break;
r[++j] = a->dp[i] >> s;
while (s + 64 <= DIGIT_BIT) {
s += 64;
r[j] &= 0xffffffffffffffffl;
if (j + 1 >= max)
break;
if (s < DIGIT_BIT)
r[++j] = a->dp[i] >> s;
else
r[++j] = 0;
}
s = DIGIT_BIT - s;
}
for (j++; j < max; j++)
r[j] = 0;
#else
int i, j = 0, s = 0;
r[0] = 0;
for (i = 0; i < a->used && j < max; i++) {
r[j] |= ((sp_digit)a->dp[i]) << s;
if (s + DIGIT_BIT >= 64) {
r[j] &= 0xffffffffffffffffl;
if (j + 1 >= max)
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 < max; j++)
r[j] = 0;
#endif
}
/* Write r as big endian to byte aray.
* 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, s = 0, b;
j = 2048 / 8 - 1;
a[j] = 0;
for (i=0; i<32 && j>=0; i++) {
b = 0;
a[j--] |= r[i] << s; b += 8 - s;
if (j < 0)
break;
while (b < 64) {
a[j--] = r[i] >> b; b += 8;
if (j < 0)
break;
}
s = 8 - (b - 64);
if (j >= 0)
a[j] = 0;
if (s != 0)
j++;
}
}
/* Multiply a and b into r. (r = a * b)
*
* r A single precision integer.
* a A single precision integer.
* b A single precision integer.
*/
SP_NOINLINE static void sp_2048_mul_16(sp_digit* r, const sp_digit* a,
const sp_digit* b)
{
sp_digit tmp[16];
__asm__ __volatile__ (
"# A[0] * B[0]\n\t"
"movq 0(%[b]), %%rax\n\t"
"mulq 0(%[a])\n\t"
"xorq %%r8, %%r8\n\t"
"movq %%rax, (%[tmp])\n\t"
"movq %%rdx, %%rcx\n\t"
"# A[0] * B[1]\n\t"
"movq 8(%[b]), %%rax\n\t"
"mulq 0(%[a])\n\t"
"xorq %%rbx, %%rbx\n\t"
"addq %%rax, %%rcx\n\t"
"adcq %%rdx, %%r8\n\t"
"adcq $0, %%rbx\n\t"
"# A[1] * B[0]\n\t"
"movq 0(%[b]), %%rax\n\t"
"mulq 8(%[a])\n\t"
"addq %%rax, %%rcx\n\t"
"adcq %%rdx, %%r8\n\t"
"adcq $0, %%rbx\n\t"
"movq %%rcx, 8(%[tmp])\n\t"
"# A[0] * B[2]\n\t"
"movq 16(%[b]), %%rax\n\t"
"mulq 0(%[a])\n\t"
"xorq %%rcx, %%rcx\n\t"
"addq %%rax, %%r8\n\t"
"adcq %%rdx, %%rbx\n\t"
"adcq $0, %%rcx\n\t"
"# A[1] * B[1]\n\t"
"movq 8(%[b]), %%rax\n\t"
"mulq 8(%[a])\n\t"
"addq %%rax, %%r8\n\t"
"adcq %%rdx, %%rbx\n\t"
"adcq $0, %%rcx\n\t"
"# A[2] * B[0]\n\t"
"movq 0(%[b]), %%rax\n\t"
"mulq 16(%[a])\n\t"
"addq %%rax, %%r8\n\t"
"adcq %%rdx, %%rbx\n\t"
"adcq $0, %%rcx\n\t"
"movq %%r8, 16(%[tmp])\n\t"
"# A[0] * B[3]\n\t"
"movq 24(%[b]), %%rax\n\t"
"mulq 0(%[a])\n\t"
"xorq %%r8, %%r8\n\t"
"addq %%rax, %%rbx\n\t"
"adcq %%rdx, %%rcx\n\t"
"adcq $0, %%r8\n\t"
"# A[1] * B[2]\n\t"
"movq 16(%[b]), %%rax\n\t"
"mulq 8(%[a])\n\t"
"addq %%rax, %%rbx\n\t"
"adcq %%rdx, %%rcx\n\t"
"adcq $0, %%r8\n\t"
"# A[2] * B[1]\n\t"
"movq 8(%[b]), %%rax\n\t"
"mulq 16(%[a])\n\t"
"addq %%rax, %%rbx\n\t"
"adcq %%rdx, %%rcx\n\t"
"adcq $0, %%r8\n\t"
"# A[3] * B[0]\n\t"
"movq 0(%[b]), %%rax\n\t"
"mulq 24(%[a])\n\t"
"addq %%rax, %%rbx\n\t"
"adcq %%rdx, %%rcx\n\t"
"adcq $0, %%r8\n\t"
"movq %%rbx, 24(%[tmp])\n\t"
"# A[0] * B[4]\n\t"
"movq 32(%[b]), %%rax\n\t"
"mulq 0(%[a])\n\t"
"xorq %%rbx, %%rbx\n\t"
"addq %%rax, %%rcx\n\t"
"adcq %%rdx, %%r8\n\t"
"adcq $0, %%rbx\n\t"
"# A[1] * B[3]\n\t"
"movq 24(%[b]), %%rax\n\t"
"mulq 8(%[a])\n\t"
"addq %%rax, %%rcx\n\t"
"adcq %%rdx, %%r8\n\t"
"adcq $0, %%rbx\n\t"
"# A[2] * B[2]\n\t"
"movq 16(%[b]), %%rax\n\t"
"mulq 16(%[a])\n\t"
"addq %%rax, %%rcx\n\t"
"adcq %%rdx, %%r8\n\t"
"adcq $0, %%rbx\n\t"
"# A[3] * B[1]\n\t"
"movq 8(%[b]), %%rax\n\t"
"mulq 24(%[a])\n\t"
"addq %%rax, %%rcx\n\t"
"adcq %%rdx, %%r8\n\t"
"adcq $0, %%rbx\n\t"
"# A[4] * B[0]\n\t"
"movq 0(%[b]), %%rax\n\t"
"mulq 32(%[a])\n\t"
"addq %%rax, %%rcx\n\t"
"adcq %%rdx, %%r8\n\t"
"adcq $0, %%rbx\n\t"
"movq %%rcx, 32(%[tmp])\n\t"
"# A[0] *
xiaolian90
- 粉丝: 72
- 资源: 8
最新资源
- 基于MATLAB的500kV LCC-HVDC 输电仿真 两侧交流系统电压为345kV,交流侧分别设计了相应的滤波器,直流电压等级为500kV,直流电流为2KA,直流功率为1000MVA,下面依次为整
- matlab simulink车辆防抱死制动系统ABS建模仿真 单轮 双轮
- 基于hadoop的新闻推荐系统 用户协同过滤推荐 基于大数据的新闻推荐系统 推荐原理:以用户对新闻的喜欢和收藏行为作为基础数据集,应用hadoop通过mapreduce程序进行协同过滤计算,得出用户对
- C#上位机模板程序,使用的是台达AS228主机PLC,功能齐全,自动运行页面、切页面、手动调试、参数设置页面都有
- TCR+fc型svc无功补偿仿真模型有详细资料
- 基于光风储能vsg无缝切(预同步)控制策略 前0.3秒风光储+直流负载独立运行 0.3s时,断开直流负载和直流源,风光储+VSG+交流负载合并运行 0.6s时,VSG预同步模块并网 1.3s时,改变t
- 自动驾驶图像全景分隔,基于HRnetSegmentation从训练工程到tensorRT工程部署Demo闭环一套,包含训练工程及部署工程,和环境的配置说明,已在实际项目中使用 大厂自动驾驶工程师沉淀
- MATLAB代码 风光场景生成 场景削减 概率距离削减法 蒙特卡洛法 MATLAB:基于概率距离快速削减法的风光场景生成与削减方法 参考文档:《含风光水的电厂与配电公司协调调度模型》完全复现场景削减
- 基于mppt的光伏svpwm逆变并网 通过分析光伏电池的输出特性与外部环境的关系搭建出仿真模型,引入了变步长扰动观察法实现的最大功率追踪 MPPT 控制算法 并设计三相逆变器SVPWM双闭环控制策略
- 伺服电机代码 直线电机代码 FPGA架构伺服代码 软件硬件方案, 一个fpga控制多个电机,目前一个fpga最多控制6伺服驱动,所有内容均有fpga完成,控制曲线(T曲线),位置环,速度环,电流环,低
- 三相逆变器重复控制 在simlink中搭建了逆变器的重复控制模型,滤波器环节采用了陷波器与二阶低通滤波器 逆变器输出电压的THD仅仅只有0.52% 整个仿真全部离散化,采用离散解析器,控制与采样
- 锁相环 采用simlink仿真嵌C语言实现锁相环,整个仿真没有一个模块,只有C需要写的锁相环函数 仿真结果如图所示,基于双二阶广义积分器的锁相环成功锁得电网相位 对C语言写的代码做了详尽的注释
- PWM整流器仿真 在simulink中搭建了PWM整流器,采用电压电流双闭环控制,实现了网侧电压与电流同相位,单位功率因数运行 采用基于双二阶广义积分器的锁相环,锁得电网相位 整个仿真全部离散化
- matlab代码:计及条件风险价值的电-气综合能源系统能量-备用分布鲁棒优化 关键词:wasserstein距离 CVAR条件风险价值 分布鲁棒优化 电-气综合能源 能量-备用调度 参考文档Ene
- 基于DSTATCOM无功补偿的风电并网模型 Matlab simulink 质量过硬 仿真简介: 1、2个风电:一个基于双馈风机DFIG、一个基于感应风机 2、仿真总时长30s,10s时,感应风机
- 考虑储能削峰填谷的含DG配电网可靠性评估 1、基于序贯蒙特卡洛的配电网可靠性评估; 2、基于序贯蒙特卡洛的含DG配电网可靠性评估; 3、基于区间迭代法优化储能出力进行削峰填谷; 4、基于上述内容进一
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈