return 0;
}
+/**
+ * Enter ASN.1 unsigned integer
+ *
+ * @v cursor ASN.1 object cursor
+ * @ret rc Return status code
+ */
+int asn1_enter_unsigned ( struct asn1_cursor *cursor ) {
+ int rc;
+
+ /* Enter integer */
+ if ( ( rc = asn1_enter ( cursor, ASN1_INTEGER ) ) != 0 )
+ return rc;
+
+ /* Skip initial positive sign byte if applicable */
+ if ( ( cursor->len > 1 ) &&
+ ( *( ( uint8_t * ) cursor->data ) == 0x00 ) ) {
+ cursor->data++;
+ cursor->len--;
+ }
+
+ return 0;
+}
+
/**
* Parse value of ASN.1 boolean
*
return 0;
}
-/**
- * Parse RSA integer
- *
- * @v integer Integer to fill in
- * @v raw ASN.1 cursor
- * @ret rc Return status code
- */
-static int rsa_parse_integer ( struct asn1_cursor *integer,
- const struct asn1_cursor *raw ) {
-
- /* Enter integer */
- memcpy ( integer, raw, sizeof ( *integer ) );
- asn1_enter ( integer, ASN1_INTEGER );
-
- /* Skip initial sign byte if applicable */
- if ( ( integer->len > 1 ) &&
- ( *( ( uint8_t * ) integer->data ) == 0x00 ) ) {
- integer->data++;
- integer->len--;
- }
-
- /* Fail if cursor or integer are invalid */
- if ( ! integer->len )
- return -EINVAL;
-
- return 0;
-}
-
/**
* Parse RSA modulus and exponent
*
}
/* Extract modulus */
- if ( ( rc = rsa_parse_integer ( modulus, &cursor ) ) != 0 )
+ memcpy ( modulus, &cursor, sizeof ( *modulus ) );
+ if ( ( rc = asn1_enter_unsigned ( modulus ) ) != 0 )
return rc;
asn1_skip_any ( &cursor );
asn1_skip ( &cursor, ASN1_INTEGER );
/* Extract publicExponent/privateExponent */
- if ( ( rc = rsa_parse_integer ( exponent, &cursor ) ) != 0 )
+ memcpy ( exponent, &cursor, sizeof ( *exponent ) );
+ if ( ( rc = asn1_enter_unsigned ( exponent ) ) != 0 )
return rc;
return 0;
extern int asn1_shrink_any ( struct asn1_cursor *cursor );
extern int asn1_enter_bits ( struct asn1_cursor *cursor,
unsigned int *unused );
+extern int asn1_enter_unsigned ( struct asn1_cursor *cursor );
extern int asn1_boolean ( const struct asn1_cursor *cursor );
extern int asn1_integer ( const struct asn1_cursor *cursor, int *value );
extern int asn1_compare ( const struct asn1_cursor *cursor1,