Re-add support for EC keys
@@ -29,7 +29,7 @@ static const unsigned char rsa4096Asn1Header[] =
0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00
};
-/*
+
static const unsigned char ecDsaSecp256r1Asn1Header[] =
{
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
@@ -42,7 +42,7 @@ static const unsigned char ecDsaSecp384r1Asn1Header[] =
0x30, 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x03, 0x62, 0x00
};
-*/
+
static char *getAsn1HeaderBytes(NSString *publicKeyType, NSNumber *publicKeySize)
@@ -55,6 +55,15 @@ static char *getAsn1HeaderBytes(NSString *publicKeyType, NSNumber *publicKeySize
{
return (char *)rsa4096Asn1Header;
}
+ else if (([publicKeyType isEqualToString:(NSString *)kSecAttrKeyTypeECSECPrimeRandom]) && ([publicKeySize integerValue] == 256))
+ {
+ return (char *)ecDsaSecp256r1Asn1Header;
+ }
+ else if (([publicKeyType isEqualToString:(NSString *)kSecAttrKeyTypeECSECPrimeRandom]) && ([publicKeySize integerValue] == 384))
+ {
+ return (char *)ecDsaSecp384r1Asn1Header;
+ }
+
@throw([NSException exceptionWithName:@"Unsupported public key algorithm" reason:@"Tried to generate the SPKI hash for an unsupported key algorithm" userInfo:nil]);
}
@@ -68,6 +77,15 @@ static unsigned int getAsn1HeaderSize(NSString *publicKeyType, NSNumber *publicK
{
return sizeof(rsa4096Asn1Header);
}
+ else if (([publicKeyType isEqualToString:(NSString *)kSecAttrKeyTypeECSECPrimeRandom]) && ([publicKeySize integerValue] == 256))
+ {
+ return sizeof(ecDsaSecp256r1Asn1Header);
+ }
+ else if (([publicKeyType isEqualToString:(NSString *)kSecAttrKeyTypeECSECPrimeRandom]) && ([publicKeySize integerValue] == 384))
+ {
+ return sizeof(ecDsaSecp384r1Asn1Header);
+ }
+
@throw([NSException exceptionWithName:@"Unsupported public key algorithm" reason:@"Tried to generate the SPKI hash for an unsupported key algorithm" userInfo:nil]);
}
