-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSA: add support for descryption with OAEP padding
Fixes: #89
- Loading branch information
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
set -eufx | ||
|
||
echo -n "abcde12345abcde12345" > testdata | ||
|
||
# create primary key | ||
tpm2_createprimary -c primary.ctx | ||
|
||
# create a default key | ||
tpm2_create -C primary.ctx -u key.pub -r key.priv | ||
|
||
# load the key | ||
tpm2_load -C primary.ctx -u key.pub -r key.priv -c testkey.ctx | ||
|
||
# make the key persistent | ||
HANDLE=$(tpm2_evictcontrol -c testkey.ctx | cut -d ' ' -f 2 | head -n 1) | ||
|
||
# export public key | ||
openssl pkey -provider tpm2 -propquery '?provider=tpm2' -in handle:${HANDLE} -pubout -out testkey.pub | ||
|
||
# encrypt data, no padding | ||
openssl pkeyutl -encrypt -pubin -inkey testkey.pub -pkeyopt rsa_padding_mode:oaep \ | ||
-pkeyopt rsa_oaep_md:sha256 -in testdata -out testdata.crypt | ||
|
||
# decrypt data | ||
openssl pkeyutl -provider tpm2 -propquery '?provider=tpm2' -inkey handle:${HANDLE} \ | ||
-decrypt -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 -in testdata.crypt -out testdata2 | ||
|
||
# check the decryption | ||
cmp testdata testdata2 | ||
|
||
# release the persistent key | ||
tpm2_evictcontrol -c ${HANDLE} | ||
|
||
rm primary.ctx key.pub key.priv testkey.ctx testkey.pub testdata testdata.crypt \ | ||
testdata2 |
File renamed without changes.