Skip to content

Commit

Permalink
[Example] Add actions rsasha34 & rsapsssha34
Browse files Browse the repository at this point in the history
Added new actions for verifying SHA-384 RSA PKCS#1 v1.5 and RSASSA-PSS signature
  • Loading branch information
smlu committed Dec 14, 2023
1 parent 4a9e828 commit 9218360
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 8 deletions.
46 changes: 46 additions & 0 deletions examples/helloack/bin/helloack.abi
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@
}
]
},
{
"name": "check_rsa_pss_sha384",
"base": "",
"fields": [
{
"name": "pubkey",
"type": "rsa_pss_public_key_view"
},
{
"name": "msg",
"type": "bytes_view"
},
{
"name": "sig",
"type": "bytes_view"
}
]
},
{
"name": "check_rsa_pss_sha512",
"base": "",
Expand Down Expand Up @@ -209,6 +227,24 @@
}
]
},
{
"name": "check_rsa_sha384",
"base": "",
"fields": [
{
"name": "pubkey",
"type": "rsa_public_key_view"
},
{
"name": "msg",
"type": "bytes_view"
},
{
"name": "sig",
"type": "bytes_view"
}
]
},
{
"name": "check_rsa_sha512",
"base": "",
Expand Down Expand Up @@ -336,6 +372,11 @@
"type": "check_rsa_pss_sha256",
"ricardian_contract": ""
},
{
"name": "rsapsssha34",
"type": "check_rsa_pss_sha384",
"ricardian_contract": ""
},
{
"name": "rsapsssha512",
"type": "check_rsa_pss_sha512",
Expand All @@ -351,6 +392,11 @@
"type": "check_rsa_sha256",
"ricardian_contract": ""
},
{
"name": "rsasha34",
"type": "check_rsa_sha384",
"ricardian_contract": ""
},
{
"name": "rsasha512",
"type": "check_rsa_sha512",
Expand Down
Binary file modified examples/helloack/bin/helloack.wasm
Binary file not shown.
20 changes: 20 additions & 0 deletions examples/helloack/include/helloack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ struct [[eosio::contract]] helloack : public eosio::contract {
[[eosio::action("rsapsssha2"), eosio::read_only]]
void check_rsa_pss_sha256(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig);

/**
* Action verifies RSA PKCS v1.5 SHA-384 signature.
* Action fails if signature is invalid
* @param pubkey - RSA public key
* @param msg - signed message
* @param sig - RSA PKCS v1.5 SHA-384 signature
*/
[[eosio::action("rsasha34"), eosio::read_only]]
void check_rsa_sha384(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig);

/**
* Action verifies RSA PSS MGF1 SHA-384 signature.
* Action fails if signature is invalid
* @param pubkey - RSA-PSS public key
* @param msg - signed message
* @param sig - RSA-PSS MGF1 SHA-384 signature
*/
[[eosio::action("rsapsssha34"), eosio::read_only]]
void check_rsa_pss_sha384(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig);

/**
* Action verifies RSA PKCS v1.5 SHA-512 signature.
* Action fails if signature is invalid
Expand Down
35 changes: 27 additions & 8 deletions examples/helloack/src/helloack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ack/ec.hpp>
#include <ack/ec_curve.hpp>
#include <ack/ecdsa.hpp>
#include <ack/sha.hpp>

#include <helloack.hpp>
#include <bt.hpp>
Expand Down Expand Up @@ -37,7 +38,7 @@ void helloack::check_ecdsa_secp256r1_sha256(bytes_view qx, bytes_view qy, bytes_
[[eosio::action("rsasha1"), eosio::read_only]]
void helloack::check_rsa_sha1(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
const auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
assert_rsa_sha1( pubkey, md, sig,
"RSA PKCS v1.5 SHA-1 signature verification failed"
);
Expand All @@ -46,34 +47,52 @@ void helloack::check_rsa_sha1(rsa_public_key_view pubkey, bytes_view msg, bytes_
[[eosio::action("rsapsssha1"), eosio::read_only]]
void helloack::check_rsa_pss_sha1(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
const auto md = eosio::sha1( reinterpret_cast<const char*>( msg.data() ), msg.size() );
assert_rsa_pss_sha1( pubkey, md, sig,
"RSA PSS SHA-1 signature verification failed"
);
}

[[eosio::action("rsasha2")]]
[[eosio::action("rsasha2"), eosio::read_only]]
void helloack::check_rsa_sha256(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
const auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
assert_rsa_sha256( pubkey, md, sig,
"RSA PKCS v1.5 SHA-256 signature verification failed"
);
}

[[eosio::action("rsapsssha2")]]
[[eosio::action("rsapsssha2"), eosio::read_only]]
void helloack::check_rsa_pss_sha256(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
const auto md = eosio::sha256( reinterpret_cast<const char*>( msg.data() ), msg.size() );
assert_rsa_pss_sha256( pubkey, md, sig,
"RSA PSS SHA-256 signature verification failed"
);
}

[[eosio::action("rsasha34"), eosio::read_only]]
void helloack::check_rsa_sha384(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
const auto md = sha384( msg );
assert_rsa_sha384( pubkey, md, sig,
"RSA PKCS v1.5 SHA-384 signature verification failed"
);
}

[[eosio::action("rsapsssha34"), eosio::read_only]]
void helloack::check_rsa_pss_sha384(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
const auto md = sha384( msg );
assert_rsa_pss_sha384( pubkey, md, sig,
"RSA PSS SHA-384 signature verification failed"
);
}

[[eosio::action("rsasha512"), eosio::read_only]]
void helloack::check_rsa_sha512(rsa_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
const auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
assert_rsa_sha512( pubkey, md, sig,
"RSA PKCS v1.5 SHA-512 signature verification failed"
);
Expand All @@ -82,7 +101,7 @@ void helloack::check_rsa_sha512(rsa_public_key_view pubkey, bytes_view msg, byte
[[eosio::action("rsapsssha512"), eosio::read_only]]
void helloack::check_rsa_pss_sha512(rsa_pss_public_key_view pubkey, bytes_view msg, bytes_view sig)
{
auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
const auto md = eosio::sha512( reinterpret_cast<const char*>( msg.data() ), msg.size() );
assert_rsa_pss_sha512( pubkey, md, sig,
"RSA PSS SHA-512 signature verification failed"
);
Expand Down

0 comments on commit 9218360

Please sign in to comment.