Skip to content

Commit 8f5c092

Browse files
authored
Merge pull request #10 from ZeroPass/develop
Add SHA-384 RSA PKCS#1v1.5 & RSASSA-PSS signature verification functions && Fix bugs & Optimize
2 parents e42d326 + c245400 commit 8f5c092

32 files changed

+56440
-12005
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required( VERSION 3.14 )
22
project(
33
ack
44
LANGUAGES CXX
5-
VERSION 0.4.0
5+
VERSION 0.5.0
66
)
77

88
option( ACK_NO_INTRINSICS "Don't use intrinsics" OFF )
@@ -50,10 +50,11 @@ if ( ACK_BUILD_TESTS )
5050

5151
include (CTest)
5252
enable_testing()
53-
add_test( ack_tests ${CMAKE_BINARY_DIR}/tests/ack_tests )
53+
add_test( ack_gen_tests ${CMAKE_BINARY_DIR}/tests/ack_gen_tests )
54+
add_test( ack_rsa_tests ${CMAKE_BINARY_DIR}/tests/ack_rsa_tests )
55+
add_test( ack_ecc_tests ${CMAKE_BINARY_DIR}/tests/ack_ecc_tests )
5456
endif( ACK_BUILD_TESTS )
5557

56-
5758
message( "No intrinsics................${ACK_NO_INTRINSICS}" )
5859
message( "Building examples............${ACK_BUILD_EXAMPLES}" )
5960
message( "Building tests...............${ACK_BUILD_TESTS}" )

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# AntelopeIO Cryptography Kits
2-
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
3-
[![build](https://github.com/ZeroPass/antelope.ck/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/ZeroPass/antelope.ck/actions/workflows/build.yml)
4-
[![tests](https://github.com/ZeroPass/antelope.ck/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/ZeroPass/antelope.ck/actions/workflows/tests.yml)
2+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE)
3+
[![build](https://img.shields.io/github/actions/workflow/status/ZeroPass/ack/build.yml?branch=master&logo=github&style=for-the-badge)](https://github.com/ZeroPass/ack/actions/workflows/build.yml)
4+
[![tests](https://img.shields.io/github/actions/workflow/status/ZeroPass/ack/tests.yml?label=Tests&branch=master&logo=github&style=for-the-badge)](https://github.com/ZeroPass/ack/actions/workflows/tests.yml)
5+
56

67
[AntelopeIO](https://github.com/antelopeIO) Cryptography Library is a header-only library designed for use in smart contracts. The library includes implementations of ECC primitives and ECDSA verification algorithms, as well as RSA PKCS v1.5 & RSASSA-PSS signature verification algorithms, SHA-384 and Keccak hash algorithms: SHA3-256, SHA3-384, SHA3-512, SHAKE-128, and SHAKE-256.
78

@@ -39,6 +40,8 @@ The [ack/rsa.hpp](include/ack/rsa.hpp) header file defines the RSA PKCS v1.5 sig
3940
- `assert_rsa_sha1` - fails transaction if RSA signature is not valid for the provided SHA-1 hash.
4041
- `verify_rsa_sha256` - checks if RSA signature is valid for the provided SHA-256 hash.
4142
- `assert_rsa_sha256` - fails transaction if RSA signature is not valid for the provided SHA-256 hash.
43+
- `verify_rsa_sha384` - checks if RSA signature is valid for the provided SHA-384 hash.
44+
- `assert_rsa_sha384` - fails transaction if RSA signature is not valid for the provided SHA-384 hash.
4245
- `verify_rsa_sha512` - checks if RSA signature is valid for the provided SHA-512 hash.
4346
- `assert_rsa_sha512` - fails transaction if RSA signature is not valid for the provided SHA-512 hash.
4447

@@ -47,6 +50,8 @@ the RSASSA-PSS signature verification functions for *SHA-1*, *SHA-256* and *SHA-
4750
- `assert_rsa_pss_sha1` - fails transaction if RSASSA-PSS MGF1 signature is not valid for the provided SHA-1 hash.
4851
- `verify_rsa_pss_sha256` - checks if RSASSA-PSS MGF1 signature is valid for the provided SHA-256 hash.
4952
- `assert_rsa_pss_sha256` - fails transaction if RSASSA-PSS MGF1 signature is not valid for the provided SHA-256 hash.
53+
- `verify_rsa_pss_sha384` - checks if RSASSA-PSS MGF1 signature is valid for the provided SHA-384 hash.
54+
- `assert_rsa_pss_sha384` - fails transaction if RSASSA-PSS MGF1 signature is not valid for the provided SHA-384 hash.
5055
- `verify_rsa_pss_sha512` - checks if RSASSA-PSS MGF1 signature is valid for the provided SHA-512 hash.
5156
- `assert_rsa_pss_sha512` - fails transaction if RSASSA-PSS MGF1 signature is not valid for the provided SHA-512 hash.
5257

@@ -83,8 +88,7 @@ FIPS 180-4: [https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-P
8388
To use antelope.ck library in your project, it is recommended to use [CMake](https://cmake.org/) and configure your project to use the external `ack` project. E.g.: using [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) or copy the library folder to your project and point cmake to it with [add_subdirectory](https://cmake.org/cmake/help/latest/command/add_subdirectory.html).
8489
If only pure WASM implementation is desired configure your CMake project with `ACK_NO_INTRINSICS=ON` option before including ack library. This will exclude specialized intrinsics such as `eosio::mod_exp` from being used by the library, and instead, a software implementation will be used.
8590

86-
If configured correctly, you should be able to add the antelope.ck library to your [CMake](https://cmake.org/) project using command `add_library(<your_project> ack)` and include it in your code using the header file: `#include <ack/ack.hpp>`.
87-
91+
If configured correctly, you should be able to add the `ack` library to your [CMake](https://cmake.org/) project using command `add_library(<your_project> ack)` and include it in your code using the header file: `#include <ack/ack.hpp>`.
8892

8993
**Example:**
9094
```cpp

examples/helloack/bin/helloack.abi

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@
155155
}
156156
]
157157
},
158+
{
159+
"name": "check_rsa_pss_sha384",
160+
"base": "",
161+
"fields": [
162+
{
163+
"name": "pubkey",
164+
"type": "rsa_pss_public_key_view"
165+
},
166+
{
167+
"name": "msg",
168+
"type": "bytes_view"
169+
},
170+
{
171+
"name": "sig",
172+
"type": "bytes_view"
173+
}
174+
]
175+
},
158176
{
159177
"name": "check_rsa_pss_sha512",
160178
"base": "",
@@ -209,6 +227,24 @@
209227
}
210228
]
211229
},
230+
{
231+
"name": "check_rsa_sha384",
232+
"base": "",
233+
"fields": [
234+
{
235+
"name": "pubkey",
236+
"type": "rsa_public_key_view"
237+
},
238+
{
239+
"name": "msg",
240+
"type": "bytes_view"
241+
},
242+
{
243+
"name": "sig",
244+
"type": "bytes_view"
245+
}
246+
]
247+
},
212248
{
213249
"name": "check_rsa_sha512",
214250
"base": "",
@@ -336,6 +372,11 @@
336372
"type": "check_rsa_pss_sha256",
337373
"ricardian_contract": ""
338374
},
375+
{
376+
"name": "rsapsssha34",
377+
"type": "check_rsa_pss_sha384",
378+
"ricardian_contract": ""
379+
},
339380
{
340381
"name": "rsapsssha512",
341382
"type": "check_rsa_pss_sha512",
@@ -351,6 +392,11 @@
351392
"type": "check_rsa_sha256",
352393
"ricardian_contract": ""
353394
},
395+
{
396+
"name": "rsasha34",
397+
"type": "check_rsa_sha384",
398+
"ricardian_contract": ""
399+
},
354400
{
355401
"name": "rsasha512",
356402
"type": "check_rsa_sha512",
183 KB
Binary file not shown.

examples/helloack/include/helloack.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ struct [[eosio::contract]] helloack : public eosio::contract {
7070
[[eosio::action("rsapsssha2"), eosio::read_only]]
7171
void check_rsa_pss_sha256(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig);
7272

73+
/**
74+
* Action verifies RSA PKCS v1.5 SHA-384 signature.
75+
* Action fails if signature is invalid
76+
* @param pubkey - RSA public key
77+
* @param msg - signed message
78+
* @param sig - RSA PKCS v1.5 SHA-384 signature
79+
*/
80+
[[eosio::action("rsasha34"), eosio::read_only]]
81+
void check_rsa_sha384(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig);
82+
83+
/**
84+
* Action verifies RSA PSS MGF1 SHA-384 signature.
85+
* Action fails if signature is invalid
86+
* @param pubkey - RSA-PSS public key
87+
* @param msg - signed message
88+
* @param sig - RSA-PSS MGF1 SHA-384 signature
89+
*/
90+
[[eosio::action("rsapsssha34"), eosio::read_only]]
91+
void check_rsa_pss_sha384(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig);
92+
7393
/**
7494
* Action verifies RSA PKCS v1.5 SHA-512 signature.
7595
* Action fails if signature is invalid

examples/helloack/src/helloack.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ack/ec.hpp>
66
#include <ack/ec_curve.hpp>
77
#include <ack/ecdsa.hpp>
8+
#include <ack/sha.hpp>
89

910
#include <helloack.hpp>
1011
#include <bt.hpp>
@@ -37,43 +38,61 @@ void helloack::check_ecdsa_secp256r1_sha256(bytes_view qx, bytes_view qy, bytes_
3738
[[eosio::action("rsasha1"), eosio::read_only]]
3839
void helloack::check_rsa_sha1(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
3940
{
40-
auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
41-
assert_rsa_sha1_assert( pubkey, md, sig,
41+
const auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
42+
assert_rsa_sha1( pubkey, md, sig,
4243
"RSA PKCS v1.5 SHA-1 signature verification failed"
4344
);
4445
}
4546

4647
[[eosio::action("rsapsssha1"), eosio::read_only]]
4748
void helloack::check_rsa_pss_sha1(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
4849
{
49-
auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
50+
const auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
5051
assert_rsa_pss_sha1( pubkey, md, sig,
5152
"RSA PSS SHA-1 signature verification failed"
5253
);
5354
}
5455

55-
[[eosio::action("rsasha2")]]
56+
[[eosio::action("rsasha2"), eosio::read_only]]
5657
void helloack::check_rsa_sha256(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
5758
{
58-
auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
59+
const auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
5960
assert_rsa_sha256( pubkey, md, sig,
6061
"RSA PKCS v1.5 SHA-256 signature verification failed"
6162
);
6263
}
6364

64-
[[eosio::action("rsapsssha2")]]
65+
[[eosio::action("rsapsssha2"), eosio::read_only]]
6566
void helloack::check_rsa_pss_sha256(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
6667
{
67-
auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
68+
const auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
6869
assert_rsa_pss_sha256( pubkey, md, sig,
6970
"RSA PSS SHA-256 signature verification failed"
7071
);
7172
}
7273

74+
[[eosio::action("rsasha34"), eosio::read_only]]
75+
void helloack::check_rsa_sha384(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
76+
{
77+
const auto md = sha384( msg );
78+
assert_rsa_sha384( pubkey, md, sig,
79+
"RSA PKCS v1.5 SHA-384 signature verification failed"
80+
);
81+
}
82+
83+
[[eosio::action("rsapsssha34"), eosio::read_only]]
84+
void helloack::check_rsa_pss_sha384(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
85+
{
86+
const auto md = sha384( msg );
87+
assert_rsa_pss_sha384( pubkey, md, sig,
88+
"RSA PSS SHA-384 signature verification failed"
89+
);
90+
}
91+
7392
[[eosio::action("rsasha512"), eosio::read_only]]
7493
void helloack::check_rsa_sha512(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
7594
{
76-
auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
95+
const auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
7796
assert_rsa_sha512( pubkey, md, sig,
7897
"RSA PKCS v1.5 SHA-512 signature verification failed"
7998
);
@@ -82,7 +101,7 @@ void helloack::check_rsa_sha512(rsa_public_key_view pubkey, bytes_view msg, byte
82101
[[eosio::action("rsapsssha512"), eosio::read_only]]
83102
void helloack::check_rsa_pss_sha512(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
84103
{
85-
auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
104+
const auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
86105
assert_rsa_pss_sha512( pubkey, md, sig,
87106
"RSA PSS SHA-512 signature verification failed"
88107
);
@@ -92,7 +111,7 @@ void helloack::check_rsa_pss_sha512(rsa_pss_public_key_view pubkey, bytes_view m
92111
void helloack::bt_rsa_1024_sha1()
93112
{
94113
constexpr auto pubkey = rsa_public_key_view( rsa_1024_sha1::mod, rsa_1024_sha1::exp );
95-
assert_rsa_sha1_assert( pubkey, rsa_1024_sha1::md, rsa_1024_sha1::sig,
114+
assert_rsa_sha1( pubkey, rsa_1024_sha1::md, rsa_1024_sha1::sig,
96115
"RSA 1024 PKCS v1.5 SHA-1 signature verification failed"
97116
);
98117
}
@@ -101,7 +120,7 @@ void helloack::bt_rsa_1024_sha1()
101120
void helloack::bt_rsa_2048_sha1()
102121
{
103122
constexpr auto pubkey = rsa_public_key_view( rsa_2048_sha1::mod, rsa_2048_sha1::exp );
104-
assert_rsa_sha1_assert( pubkey, rsa_2048_sha1::md, rsa_2048_sha1::sig,
123+
assert_rsa_sha1( pubkey, rsa_2048_sha1::md, rsa_2048_sha1::sig,
105124
"RSA 2048 PKCS v1.5 SHA-1 signature verification failed"
106125
);
107126
}

0 commit comments

Comments
 (0)