Skip to content

Commit

Permalink
Encap/decap in pkeyutl - tests
Browse files Browse the repository at this point in the history
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Viktor Dukhovni <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#25127)
  • Loading branch information
beldmit committed Aug 13, 2024
1 parent 14fa2f5 commit bd3b24c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions test/decap_out.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
6�W�����n���;������m� ĥ�B[H���#�Ӈ(��h�] :\�P��x�e���b��)G�f��"��˭f� ��J�)����� {�Hm�\P ú�+�P޸%��/jϙ%�؆�<_�~�
K�JEh����lEa�:�(��/\Ѯ�b��î�� ��-g,AY��4�
l��t�N�)~\�HU4y� }qJ�� �t# ��}.��T���?��ϊ��cD=�L��nmv�{��ſԋȣ�
4 changes: 4 additions & 0 deletions test/encap_out.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
�:��y�Đ�5����[�2�<��?��qժ1�������>Y�M寬3P�
��O�2r�ي��Ad" G�m�2m��7x��h�7-�@:?N��rSꋜK����`�t�ɟ��xi�头' Mh��3r���ڃ�Sd��O���HT�F��
��kZ'x�F�K�x�q"���l@04E�����;c�iA}U��� P6�k0���%D��L�.U��aO�(L�I��Q���A
�[�uԞ�4s$���%t�B
3 changes: 3 additions & 0 deletions test/encap_secret.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
6�W�����n���;������m� ĥ�B[H���#�Ӈ(��h�] :\�P��x�e���b��)G�f��"��˭f� ��J�)����� {�Hm�\P ú�+�P޸%��/jϙ%�؆�<_�~�
K�JEh����lEa�:�(��/\Ѯ�b��î�� ��-g,AY��4�
l��t�N�)~\�HU4y� }qJ�� �t# ��}.��T���?��ϊ��cD=�L��nmv�{��ſԋȣ�
34 changes: 32 additions & 2 deletions test/recipes/20-test_pkeyutl.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use File::Spec;
use File::Basename;
use OpenSSL::Test qw/:DEFAULT srctop_file ok_nofips/;
use OpenSSL::Test::Utils;
use File::Compare qw/compare_text/;
use File::Compare qw/compare_text compare/;

setup("test_pkeyutl");

plan tests => 14;
plan tests => 19;

# For the tests below we use the cert itself as the TBS file

Expand Down Expand Up @@ -200,3 +200,33 @@ SKIP: {
"-rawin");
};
}

#Encap/decap tests
# openssl pkeyutl -encap -pubin -inkey rsa_pub.pem -secret secret.bin -out encap_out.bin
# openssl pkeyutl -decap -inkey rsa_priv.pem -in encap_out.bin -out decap_out.bin
# decap_out is equal to secret
SKIP: {
skip "RSA is not supported by this OpenSSL build", 3
if disabled("rsa");

# Self-compat
ok(run(app(([ 'openssl', 'pkeyutl', '-encap', '-pubin', '-kemop', 'RSASVE',
'-inkey', srctop_file('test', 'testrsa2048pub.pem'),
'-out', 'encap_out.bin', '-secret', 'secret.bin']))),
"RSA pubkey encapsulation");
ok(run(app(([ 'openssl', 'pkeyutl', '-decap', '-kemop', 'RSASVE',
'-inkey', srctop_file('test', 'testrsa2048.pem'),
'-in', 'encap_out.bin', '-out', 'decap_out.bin']))),
"RSA pubkey decapsulation");
is(compare("secret.bin", "decap_out.bin"), 0, "Secret is correctly decapsulated");

# Pregenerated
ok(run(app(([ 'openssl', 'pkeyutl', '-decap', '-kemop', 'RSASVE',
'-inkey', srctop_file('test', 'testrsa2048.pem'),
'-in', srctop_file('test', 'encap_out.bin'), '-out', 'decap_out_etl.bin']))),
"RSA pubkey decapsulation - pregenerated");

is(compare(srctop_file('test', 'encap_secret.bin'), "decap_out_etl.bin"), 0,
"Secret is correctly decapsulated - pregenerated");
}

0 comments on commit bd3b24c

Please sign in to comment.