From 56a7684023cc9cd1da93beb2a46e5bf4704387e0 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 22 Mar 2012 15:31:27 +0000 Subject: [PATCH] - Added alternative for SHA1 signature structure to check for (without NULL) --- include/polarssl/rsa.h | 7 +++++++ library/rsa.c | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/include/polarssl/rsa.h b/include/polarssl/rsa.h index 629aa0fab..513b0379f 100644 --- a/include/polarssl/rsa.h +++ b/include/polarssl/rsa.h @@ -114,6 +114,13 @@ ASN1_STR_NULL "\x00" \ ASN1_STR_OCTET_STRING "\x14" +#define ASN1_HASH_SHA1_ALT \ + ASN1_STR_CONSTRUCTED_SEQUENCE "\x1F" \ + ASN1_STR_CONSTRUCTED_SEQUENCE "\x07" \ + ASN1_STR_OID "\x05" \ + OID_HASH_ALG_SHA1 \ + ASN1_STR_OCTET_STRING "\x14" + #define ASN1_HASH_SHA2X \ ASN1_STR_CONSTRUCTED_SEQUENCE "\x11" \ ASN1_STR_CONSTRUCTED_SEQUENCE "\x0d" \ diff --git a/library/rsa.c b/library/rsa.c index ed1f45b25..72806e17e 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -860,6 +860,14 @@ int rsa_pkcs1_verify( rsa_context *ctx, len = siglen - ( p - buf ); + if( len == 33 && hash_id == SIG_RSA_SHA1 ) + { + if( memcmp( p, ASN1_HASH_SHA1_ALT, 13 ) == 0 && + memcmp( p + 13, hash, 20 ) == 0 ) + return( 0 ); + else + return( POLARSSL_ERR_RSA_VERIFY_FAILED ); + } if( len == 34 ) { c = p[13];