Skip to content

Commit

Permalink
Squashed 'security' changes from d4c6e8b..9ba8ba0 (#472)
Browse files Browse the repository at this point in the history
9ba8ba0 Cleanup 1028 (Xilinx#119)
715ca77 update doc (Xilinx#118)
bd2a926 Issue#111, solve timing issue, apply jacobian, reduce latency. (Xilinx#114)

Co-authored-by: sdausr <sdausr@xilinx.com>
  • Loading branch information
2 people authored and GitHub Enterprise committed Oct 29, 2021
1 parent f2133c7 commit 82c1498
Show file tree
Hide file tree
Showing 25 changed files with 2,691 additions and 417 deletions.
409 changes: 0 additions & 409 deletions security/L1/include/xf_security/ecdsa.hpp

This file was deleted.

875 changes: 875 additions & 0 deletions security/L1/include/xf_security/ecdsa_nistp256.hpp

Large diffs are not rendered by default.

846 changes: 846 additions & 0 deletions security/L1/include/xf_security/ecdsa_secp256k1.hpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions security/L1/include/xf_security/modular.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ template <int N>
ap_uint<N> monProduct(ap_uint<N> opA, ap_uint<N> opB, ap_uint<N> opM) {
ap_uint<N + 2> s = 0;
ap_uint<1> a0 = opA[0];
MON_PRODUCT_MOD:
for (int i = 0; i < N; i++) {
ap_uint<1> qa = opB[i];
ap_uint<1> qm = s[0] ^ (opB[i] & a0);
Expand Down Expand Up @@ -115,7 +116,9 @@ ap_uint<N> simpleMod(ap_uint<L> dividend, ap_uint<N> divisor) {
*/
template <int N>
ap_uint<N> productMod(ap_uint<N> opA, ap_uint<N> opB, ap_uint<N> opM) {
#pragma HLS inline off
ap_uint<N + 1> tmp = 0;
PRODUCT_MOD:
for (int i = N - 1; i >= 0; i--) {
tmp <<= 1;
if (tmp >= opM) {
Expand Down Expand Up @@ -244,7 +247,9 @@ ap_uint<N> modularInv(ap_uint<N> opA, ap_uint<N> opM) {
ap_uint<N + 1> r = 0;
ap_uint<32> k = 0;

INV_MOD_I:
while (v > 0) {
#pragma HLS loop_tripcount max = 256
if (u[0] == 0) {
u >>= 1;
s <<= 1;
Expand Down Expand Up @@ -272,7 +277,9 @@ ap_uint<N> modularInv(ap_uint<N> opA, ap_uint<N> opM) {

k -= N;

INV_MOD_II:
for (int i = 0; i < k; i++) {
#pragma HLS loop_tripcount max = 256
if (r[0] == 1) {
r += opM;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ runhls: data setup | check_vivado check_vpp
$(HLS) -f run_hls.tcl;

clean:
rm -rf settings.tcl *_hls.log ecc_test.prj
rm -rf settings.tcl *_hls.log ecdsa_nistp256_sign_test.prj

# Used by Jenkins test
cleanall: clean
Expand Down
65 changes: 65 additions & 0 deletions security/L1/tests/ecdsa_nistp256_sign/description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "Xilinx ECDSA NISTP256 Sign",
"description": "",
"flow": "hls",
"platform_whitelist": [
"u200",
"aws-vu9p-f1",
"vck190"
],
"platform_blacklist": [],
"part_whitelist": [],
"part_blacklist": [],
"project": "ecdsa_nistp256_sign_test",
"solution": "solution1",
"clock": "3.33",
"topfunction": "test",
"top": {
"source": [
"test.cpp"
],
"cflags": "-I${XF_PROJ_ROOT}/L1/include"
},
"testbench": {
"source": [
"test.cpp"
],
"cflags": "-I${XF_PROJ_ROOT}/L1/include",
"argv": {},
"stdmath": false
},
"testinfo": {
"disable": false,
"jobs": [
{
"index": 0,
"dependency": [],
"env": "",
"cmd": "",
"max_memory_MB": {
"hls_vivado_syn": 16384,
"hls_csim": 10240,
"hls_cosim": 16384,
"hls_vivado_impl": 16384,
"hls_csynth": 10240
},
"max_time_min": {
"hls_vivado_syn": 420,
"hls_csim": 60,
"hls_cosim": 420,
"hls_vivado_impl": 420,
"hls_csynth": 60
}
}
],
"targets": [
"hls_csim",
"hls_csynth",
"hls_cosim",
"hls_vivado_syn",
"hls_vivado_impl"
],
"category": "canary"
},
"clock_uncertainty": 1.05
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

source settings.tcl

set PROJ "ecc_test.prj"
set PROJ "ecdsa_nistp256_sign_test.prj"
set SOLN "solution1"

if {![info exists CLKP]} {
Expand Down
52 changes: 52 additions & 0 deletions security/L1/tests/ecdsa_nistp256_sign/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2019 Xilinx, 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.
*/

#include "xf_security/ecdsa_nistp256.hpp"
#ifndef __SYNTHESIS__
#include <iostream>
#endif

void test(ap_uint<256> hash, ap_uint<256> k, ap_uint<256> privateKey, ap_uint<256>& r, ap_uint<256>& s, bool& kValid) {
xf::security::nistp256Sign(hash, k, privateKey, r, s);
}

#ifndef __SYNTHESIS__
int main() {
ap_uint<256> m = ap_uint<256>("0x44acf6b7e36c1342c2c5897204fe09504e1e2efb1a900377dbc4e7a6a133ec56");
ap_uint<256> privateKey = ap_uint<256>("0x519b423d715f8b581f4fa8ee59f4771a5b44c8130b4e3eacca54a56dda72b464");
ap_uint<256> k = ap_uint<256>("0x94a1bbb14b906a61a280f245f9e93c7f3b4a6247824f5d33b9670787642a68de");
ap_uint<256> gold_r = ap_uint<256>("0xf3ac8061b514795b8843e3d6629527ed2afd6b1f6a555a7acabb5e6f79c8c2ac");
ap_uint<256> gold_s = ap_uint<256>("0x8bf77819ca05a6b2786c76262bf7371cef97b218e96f175a3ccdda2acc058903");

ap_uint<256> r, s;
bool kValid;

int i = 0;
for (i; i < 5; i++) {
test(m, k, privateKey, r, s, kValid);
}

if (gold_r != r || gold_s != s) {
std::cout << std::hex << "r: " << r << std::endl;
std::cout << std::hex << "gold_r: " << gold_r << std::endl;
std::cout << std::hex << "s: " << s << std::endl;
std::cout << std::hex << "gold_s: " << gold_s << std::endl;
return 1;
} else {
return 0;
}
}
#endif
Loading

0 comments on commit 82c1498

Please sign in to comment.