Advertisement
AnthonyCagliano

Untitled

Apr 11th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. uint8_t asn1_demo[] = {0x30,0x81,0x9f,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xc0,0x3c,0xa0,0x1c,0x0b,0x0e,0xbe,0xb0,0x64,0x62,0xfc,0x2e,0x0e,0x8d,0x04,0x9d,0xc1,0xa7,0xc7,0xce,0x88,0x8d,0x85,0x87,0x6a,0x41,0x93,0x45,0x25,0x23,0x25,0x38,0x74,0xce,0x4f,0xf1,0x46,0xf5,0x3b,0x94,0x19,0xb2,0x1d,0x6d,0xfc,0xa0,0x46,0x04,0x64,0xc6,0xb2,0x33,0x77,0x2f,0xb9,0x89,0x33,0x6a,0xce,0x84,0x8a,0x5a,0xff,0x88,0x1f,0x03,0x38,0x31,0x1d,0xe6,0x08,0xdd,0xd0,0xae,0x86,0xfd,0xf5,0xd9,0x25,0x4f,0x82,0x1c,0x93,0xa4,0xcc,0x32,0x22,0x67,0xa2,0x16,0x68,0xb9,0xd6,0xae,0xe4,0xb2,0xee,0x80,0x93,0xb1,0x4a,0x2b,0x80,0x27,0x27,0xfd,0x99,0x18,0x90,0xb6,0xe2,0x97,0x2a,0x14,0x51,0x02,0xca,0x73,0x36,0x41,0x52,0x18,0xdc,0xa8,0xe8,0x69,0x44,0x09,0x02,0x03,0x01,0x00,0x01,};
  2. // use the 'test.py' file in this example's root folder to generate more key structs for testing
  3.  
  4. int main(void)
  5. {
  6. uint8_t *data_ptr;
  7. size_t data_len=0, data_parsed = 0;
  8. uint8_t data_tag;
  9. asn1_error_t err;
  10.  
  11. sprintf(CEMU_CONSOLE, "\n\n----------------------------------\nENCODEX ASN.1 Decoder Demo\n");
  12.  
  13. // uint8_t *elem_tag, size_t *elem_len, uint8_t **elem_data
  14. while((err = cryptx_asn1_decode(&asn1_demo[data_parsed], sizeof(asn1_demo) - data_parsed, &data_tag, &data_len, &data_ptr)) == ASN1_OK){
  15.  
  16. sprintf(CEMU_CONSOLE, "RV: %u, Tag: %u, Size: %u, Addr: %u\n", err, CRYPTX_ASN1_TAGBASE(data_tag), data_len, *data_ptr);
  17. data_parsed += data_len;
  18. }
  19.  
  20. // parse ASN.1 encoded data
  21. /*
  22. This call to asn1_decode will return 3 objects.
  23. 1. pkcs#1IdString
  24. 2. nullObject
  25. 3. RSAData
  26. This is because any tag with the constructed bit set will be automatically
  27. deconstructed further, but the BIT STRING object does not have this tag set.
  28. You will need to then call asn1_decode on this object specifically to break it down further.
  29. */
  30.  
  31. /*
  32. For reasons unknown, DER encodes the integer modulus and public exponent as a BIT STRING
  33. with a single byte of 0x00 padding, followed by a SEQUENCE containing the modulus and
  34. exponent.
  35. Also the modulus itself is usually prepended with a single 0x00 byte as well.
  36. This call to asn1_decode will return 2 objects.
  37. 1. modulus
  38. 2. exponent
  39. */
  40.  
  41. // Strip the first byte of modulus and you have the information you need for
  42. // rsa_encrypt().
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement