summaryrefslogtreecommitdiffstats
path: root/src/crypto
diff options
context:
space:
mode:
authorMichael Brown2025-12-01 17:02:54 +0100
committerMichael Brown2025-12-01 17:02:54 +0100
commitd4258272c679c8bd42430fc2df57402cdc03d711 (patch)
treea3f9c691fce786a9e70aa696e9665cf68b28728c /src/crypto
parent[crypto] Pass signatures for verification as ASN.1 cursors (diff)
downloadipxe-d4258272c679c8bd42430fc2df57402cdc03d711.tar.gz
ipxe-d4258272c679c8bd42430fc2df57402cdc03d711.tar.xz
ipxe-d4258272c679c8bd42430fc2df57402cdc03d711.zip
[crypto] Construct signatures using ASN.1 builders
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/crypto_null.c3
-rw-r--r--src/crypto/rsa.c24
2 files changed, 15 insertions, 12 deletions
diff --git a/src/crypto/crypto_null.c b/src/crypto/crypto_null.c
index ca4e1b134..ee948e00d 100644
--- a/src/crypto/crypto_null.c
+++ b/src/crypto/crypto_null.c
@@ -113,7 +113,8 @@ int pubkey_null_decrypt ( const struct asn1_cursor *key __unused,
int pubkey_null_sign ( const struct asn1_cursor *key __unused,
struct digest_algorithm *digest __unused,
- const void *value __unused, void *signature __unused ) {
+ const void *value __unused,
+ struct asn1_builder *signature __unused ) {
return 0;
}
diff --git a/src/crypto/rsa.c b/src/crypto/rsa.c
index b93437518..fd6a1ef39 100644
--- a/src/crypto/rsa.c
+++ b/src/crypto/rsa.c
@@ -544,13 +544,12 @@ static int rsa_encode_digest ( struct rsa_context *context,
* @v digest Digest algorithm
* @v value Digest value
* @v signature Signature
- * @ret signature_len Signature length, or negative error
+ * @ret rc Return status code
*/
static int rsa_sign ( const struct asn1_cursor *key,
struct digest_algorithm *digest, const void *value,
- void *signature ) {
+ struct asn1_builder *signature ) {
struct rsa_context context;
- void *temp;
int rc;
DBGC ( &context, "RSA %p signing %s digest:\n",
@@ -561,24 +560,27 @@ static int rsa_sign ( const struct asn1_cursor *key,
if ( ( rc = rsa_init ( &context, key ) ) != 0 )
goto err_init;
- /* Encode digest (using the big integer output buffer as
- * temporary storage)
- */
- temp = context.output0;
- if ( ( rc = rsa_encode_digest ( &context, digest, value, temp ) ) != 0 )
+ /* Create space for encoded digest and signature */
+ if ( ( rc = asn1_grow ( signature, context.max_len ) ) != 0 )
+ goto err_grow;
+
+ /* Encode digest */
+ if ( ( rc = rsa_encode_digest ( &context, digest, value,
+ signature->data ) ) != 0 )
goto err_encode;
/* Encipher the encoded digest */
- rsa_cipher ( &context, temp, signature );
+ rsa_cipher ( &context, signature->data, signature->data );
DBGC ( &context, "RSA %p signed %s digest:\n", &context, digest->name );
- DBGC_HDA ( &context, 0, signature, context.max_len );
+ DBGC_HDA ( &context, 0, signature->data, signature->len );
/* Free context */
rsa_free ( &context );
- return context.max_len;
+ return 0;
err_encode:
+ err_grow:
rsa_free ( &context );
err_init:
return rc;