tom 2009/03/17 21:11:56 GMT
Modified files: (Branch: DEVEL_PDKIM)
exim-src/src/pdkim pdkim.h rsa.c rsa.h
Log:
more pdkim wip
Revision Changes Path
1.1.2.8 +1 -1 exim/exim-src/src/pdkim/pdkim.h
1.1.2.3 +109 -98 exim/exim-src/src/pdkim/rsa.c
1.1.2.3 +3 -4 exim/exim-src/src/pdkim/rsa.h
Index: pdkim.h
===================================================================
RCS file: /home/cvs/exim/exim-src/src/pdkim/Attic/pdkim.h,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- pdkim.h 17 Mar 2009 16:20:13 -0000 1.1.2.7
+++ pdkim.h 17 Mar 2009 21:11:56 -0000 1.1.2.8
@@ -1,5 +1,5 @@
-/* $Cambridge: exim/exim-src/src/pdkim/pdkim.h,v 1.1.2.7 2009/03/17 16:20:13 tom Exp $ */
-/* pdkim-api.h */
+/* $Cambridge: exim/exim-src/src/pdkim/pdkim.h,v 1.1.2.8 2009/03/17 21:11:56 tom Exp $ */
+/* pdkim.h */
/* -------------------------------------------------------------------------- */
/* Debugging. This can also be enabled/disabled at run-time. I recommend to
Index: rsa.c
===================================================================
RCS file: /home/cvs/exim/exim-src/src/pdkim/Attic/rsa.c,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- rsa.c 17 Mar 2009 12:57:37 -0000 1.1.2.2
+++ rsa.c 17 Mar 2009 21:11:56 -0000 1.1.2.3
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/exim-src/src/pdkim/rsa.c,v 1.1.2.2 2009/03/17 12:57:37 tom Exp $ */
+/* $Cambridge: exim/exim-src/src/pdkim/rsa.c,v 1.1.2.3 2009/03/17 21:11:56 tom Exp $ */
/*
* The RSA public-key cryptosystem
*
@@ -34,6 +34,106 @@
#include <string.h>
#include <stdio.h>
+
+/*
+ * ASN.1 DER decoding routines
+ */
+static int asn1_get_len( unsigned char **p,
+ unsigned char *end,
+ int *len )
+{
+ if( ( end - *p ) < 1 )
+ return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
+
+ if( ( **p & 0x80 ) == 0 )
+ *len = *(*p)++;
+ else
+ {
+ switch( **p & 0x7F )
+ {
+ case 1:
+ if( ( end - *p ) < 2 )
+ return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
+
+ *len = (*p)[1];
+ (*p) += 2;
+ break;
+
+ case 2:
+ if( ( end - *p ) < 3 )
+ return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
+
+ *len = ( (*p)[1] << 8 ) | (*p)[2];
+ (*p) += 3;
+ break;
+
+ default:
+ return( POLARSSL_ERR_ASN1_INVALID_LENGTH );
+ break;
+ }
+ }
+
+ if( *len > (int) ( end - *p ) )
+ return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
+
+ return( 0 );
+}
+
+static int asn1_get_tag( unsigned char **p,
+ unsigned char *end,
+ int *len, int tag )
+{
+ if( ( end - *p ) < 1 )
+ return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
+
+ if( **p != tag )
+ return( POLARSSL_ERR_ASN1_UNEXPECTED_TAG );
+
+ (*p)++;
+
+ return( asn1_get_len( p, end, len ) );
+}
+
+static int asn1_get_int( unsigned char **p,
+ unsigned char *end,
+ int *val )
+{
+ int ret, len;
+
+ if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 )
+ return( ret );
+
+ if( len > (int) sizeof( int ) || ( **p & 0x80 ) != 0 )
+ return( POLARSSL_ERR_ASN1_INVALID_LENGTH );
+
+ *val = 0;
+
+ while( len-- > 0 )
+ {
+ *val = ( *val << 8 ) | **p;
+ (*p)++;
+ }
+
+ return( 0 );
+}
+
+static int asn1_get_mpi( unsigned char **p,
+ unsigned char *end,
+ mpi *X )
+{
+ int ret, len;
+
+ if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 )
+ return( ret );
+
+ ret = mpi_read_binary( X, *p, len );
+
+ *p += len;
+
+ return( ret );
+}
+
+
/*
* Initialize an RSA context
*/
@@ -481,6 +581,15 @@
return( POLARSSL_ERR_RSA_VERIFY_FAILED );
}
+ if( len == 51 && hash_id == RSA_SHA256 )
+ {
+ if( memcmp( p, ASN1_HASH_SHA256, 19 ) == 0 &&
+ memcmp( p + 19, hash, 32 ) == 0 )
+ return( 0 );
+ else
+ return( POLARSSL_ERR_RSA_VERIFY_FAILED );
+ }
+
if( len == hashlen && hash_id == RSA_RAW )
{
if( memcmp( p, hash, hashlen ) == 0 )
@@ -503,104 +612,6 @@
&ctx->E, &ctx->N, NULL );
}
-/*
- * ASN.1 DER decoding routines
- */
-static int asn1_get_len( unsigned char **p,
- unsigned char *end,
- int *len )
-{
- if( ( end - *p ) < 1 )
- return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
-
- if( ( **p & 0x80 ) == 0 )
- *len = *(*p)++;
- else
- {
- switch( **p & 0x7F )
- {
- case 1:
- if( ( end - *p ) < 2 )
- return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
-
- *len = (*p)[1];
- (*p) += 2;
- break;
-
- case 2:
- if( ( end - *p ) < 3 )
- return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
-
- *len = ( (*p)[1] << 8 ) | (*p)[2];
- (*p) += 3;
- break;
-
- default:
- return( POLARSSL_ERR_ASN1_INVALID_LENGTH );
- break;
- }
- }
-
- if( *len > (int) ( end - *p ) )
- return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
-
- return( 0 );
-}
-
-static int asn1_get_tag( unsigned char **p,
- unsigned char *end,
- int *len, int tag )
-{
- if( ( end - *p ) < 1 )
- return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
-
- if( **p != tag )
- return( POLARSSL_ERR_ASN1_UNEXPECTED_TAG );
-
- (*p)++;
-
- return( asn1_get_len( p, end, len ) );
-}
-
-static int asn1_get_int( unsigned char **p,
- unsigned char *end,
- int *val )
-{
- int ret, len;
-
- if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 )
- return( ret );
-
- if( len > (int) sizeof( int ) || ( **p & 0x80 ) != 0 )
- return( POLARSSL_ERR_ASN1_INVALID_LENGTH );
-
- *val = 0;
-
- while( len-- > 0 )
- {
- *val = ( *val << 8 ) | **p;
- (*p)++;
- }
-
- return( 0 );
-}
-
-static int asn1_get_mpi( unsigned char **p,
- unsigned char *end,
- mpi *X )
-{
- int ret, len;
-
- if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 )
- return( ret );
-
- ret = mpi_read_binary( X, *p, len );
-
- *p += len;
-
- return( ret );
-}
-
/*
* Parse a public RSA key
Index: rsa.h
===================================================================
RCS file: /home/cvs/exim/exim-src/src/pdkim/Attic/rsa.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- rsa.h 17 Mar 2009 12:57:37 -0000 1.1.2.2
+++ rsa.h 17 Mar 2009 21:11:56 -0000 1.1.2.3
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/exim-src/src/pdkim/rsa.h,v 1.1.2.2 2009/03/17 12:57:37 tom Exp $ */
+/* $Cambridge: exim/exim-src/src/pdkim/rsa.h,v 1.1.2.3 2009/03/17 21:11:56 tom Exp $ */
/**
* \file rsa.h
*
@@ -125,10 +125,9 @@
"\x02\x1A\x05\x00\x04\x14"
#define ASN1_HASH_SHA256 \
- "\x30\x21\x30\x09" \
- "\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02" \
- "\x05\x00\x04\x20"
-
+ "\x30\x31\x30\x0d\x06\x09\x60\x86\x48" \
+ "\x01\x65\x03\x04\x02\x01\x05\x00\x04" \
+ "\x20"
/**
* \brief RSA context structure