hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

pkcs1.ha (16762B)


      1 // License: MPL-2.0
      2 // (c) 2022 Armin Preiml <apreiml@strohwolke.at>
      3 use bytes;
      4 use crypto::sha1;
      5 use crypto::sha256;
      6 use crypto::sha512;
      7 use hash;
      8 use io;
      9 
     10 const msg: [_]u8 = [
     11 	0x53, 0x53, 0x48, 0x53, 0x49, 0x47, 0x00, 0x00, 0x00, 0x03, 0x6a, 0x6f,
     12 	0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x73, 0x68, 0x61,
     13 	0x35, 0x31, 0x32, 0x00, 0x00, 0x00, 0x40, 0xce, 0x25, 0x8d, 0xf2, 0x3a,
     14 	0x14, 0xf2, 0x80, 0xeb, 0xea, 0x9b, 0xd4, 0xd7, 0xb8, 0x94, 0xce, 0x23,
     15 	0x98, 0xa8, 0x27, 0x30, 0x42, 0x61, 0x6a, 0xd2, 0x15, 0x59, 0x97, 0xc2,
     16 	0xb4, 0x79, 0x8b, 0x16, 0xdc, 0x49, 0xb5, 0x26, 0x51, 0x77, 0xe3, 0x27,
     17 	0x5c, 0xdf, 0xc0, 0xa5, 0x46, 0x97, 0xdb, 0x7b, 0x2c, 0x3b, 0x9b, 0x97,
     18 	0x3e, 0xc9, 0xca, 0xea, 0x9a, 0xcd, 0xbd, 0x2c, 0xaa, 0xcc, 0x77,
     19 ];
     20 
     21 const sig1: [_] u8 = [
     22 	0x3a, 0x29, 0x89, 0x83, 0xf5, 0xb6, 0x25, 0x0c, 0x00, 0xd4, 0x44, 0x4a,
     23 	0x16, 0xa9, 0xcf, 0xb6, 0x14, 0x3d, 0xc1, 0xa9, 0x45, 0x24, 0xb1, 0x54,
     24 	0x53, 0x2b, 0x59, 0x81, 0xf8, 0x7c, 0xdb, 0x4c, 0x16, 0xd1, 0x0e, 0x68,
     25 	0xb8, 0x1a, 0x48, 0x02, 0x3d, 0x34, 0x08, 0x14, 0xb7, 0xc1, 0x90, 0x1f,
     26 	0x4d, 0x7f, 0xbc, 0xa1, 0xef, 0x8c, 0xf0, 0x71, 0x24, 0x11, 0x27, 0xa7,
     27 	0x1c, 0xc9, 0x44, 0x11, 0x65, 0x1e, 0xca, 0xa0, 0x4b, 0xb5, 0x27, 0x67,
     28 	0xe3, 0x80, 0x4d, 0x79, 0xbf, 0x28, 0xb9, 0x85, 0xe8, 0x27, 0xad, 0x7d,
     29 	0xca, 0x2e, 0x0d, 0xb2, 0xe6, 0x42, 0x29, 0x37, 0x8b, 0xb2, 0xc3, 0x0c,
     30 	0x49, 0x9f, 0x78, 0x2c, 0x03, 0xe4, 0x2e, 0x83, 0x79, 0xb0, 0x6c, 0x09,
     31 	0xf4, 0x3c, 0xc7, 0x14, 0xfa, 0x73, 0x41, 0x28, 0x39, 0x1f, 0x8a, 0x23,
     32 	0x7b, 0x71, 0x5d, 0x15, 0x23, 0x69, 0x95, 0x1c, 0x8d, 0x50, 0x6c, 0x4e,
     33 	0x6e, 0x7d, 0xab, 0xcf, 0xab, 0xbd, 0xa2, 0xf1, 0x18, 0x2d, 0xb3, 0x70,
     34 	0x5d, 0x62, 0x45, 0xad, 0xa9, 0x1b, 0x40, 0x1f, 0xe8, 0xe1, 0x25, 0x19,
     35 	0x78, 0xfd, 0x73, 0x49, 0x45, 0x09, 0x21, 0x5c, 0x25, 0xff, 0x86, 0x1d,
     36 	0x6c, 0x63, 0xc6, 0xc1, 0xc0, 0x56, 0xe9, 0x84, 0x6d, 0x15, 0xc6, 0xcf,
     37 	0xeb, 0x33, 0xc5, 0x80, 0xda, 0x34, 0x30, 0x04, 0x92, 0x91, 0x04, 0xeb,
     38 	0x8f, 0xcb, 0x42, 0xd4, 0x41, 0x9a, 0x03, 0x86, 0x35, 0xed, 0x78, 0xa6,
     39 	0x1e, 0x95, 0x5f, 0x5e, 0x9e, 0xc0, 0x23, 0x3a, 0xd1, 0x72, 0xc3, 0x9a,
     40 	0x16, 0x6b, 0xa5, 0xc3, 0x90, 0x40, 0x1b, 0x56, 0xe3, 0xc2, 0xd5, 0x66,
     41 	0xb0, 0x86, 0xfe, 0x54, 0xb7, 0xa4, 0x51, 0xba, 0x41, 0xae, 0xb0, 0xd5,
     42 	0xad, 0x76, 0x13, 0x7b, 0xa6, 0x4d, 0x3e, 0x77, 0x59, 0x27, 0xcd, 0x31,
     43 	0x4a, 0xfb, 0xbd, 0x79, 0x9a, 0xc6, 0x9e, 0x0d, 0x45, 0x56, 0xc0, 0xcc,
     44 	0x3f, 0xdd, 0xbd, 0x2e, 0x0c, 0x11, 0xb6, 0x81, 0x14, 0xdb, 0x67, 0x78,
     45 	0x68, 0x7b, 0x0b, 0x3b, 0xf6, 0xb7, 0x00, 0x99, 0x5f, 0xda, 0xf9, 0x47,
     46 	0x97, 0xf7, 0x04, 0x8f, 0xda, 0x37, 0xbf, 0x9c, 0xbf, 0xa8, 0xe5, 0x57,
     47 	0x45, 0x7c, 0xc7, 0xf3, 0x51, 0x81, 0x95, 0xd4, 0x1b, 0xf1, 0x51, 0xfb,
     48 	0x7e, 0xad, 0xc3, 0x60, 0x78, 0x2e, 0x11, 0xe1, 0x6f, 0x10, 0x1c, 0x99,
     49 	0xe0, 0x43, 0x41, 0x58, 0x24, 0x5b, 0x0d, 0xd5, 0xae, 0x3e, 0x8b, 0x43,
     50 	0xf4, 0x1f, 0x11, 0x48, 0x16, 0xcf, 0x3b, 0x33, 0x05, 0x03, 0xdd, 0x03,
     51 	0x14, 0xe9, 0x22, 0x8b, 0xab, 0x2e, 0xe6, 0xd3, 0xaf, 0x9e, 0xf4, 0x16,
     52 	0xdf, 0xc8, 0x81, 0x21, 0xc4, 0x9e, 0x3e, 0xbd, 0x06, 0xb1, 0x7a, 0xd8,
     53 	0x3a, 0xb9, 0xd1, 0x74, 0x07, 0x2b, 0x99, 0xe6, 0x77, 0xe1, 0x99, 0x81,
     54 ];
     55 
     56 const sig256: [_]u8 = [
     57 	0x46, 0x31, 0xbd, 0xdb, 0xc9, 0x1a, 0xc4, 0x96, 0x05, 0x35, 0x8c, 0xba,
     58 	0xf0, 0xc0, 0x82, 0x84, 0xdc, 0x00, 0x5d, 0x43, 0xe2, 0x24, 0x43, 0x82,
     59 	0xee, 0xeb, 0x10, 0x69, 0xb8, 0x83, 0x07, 0xe8, 0xf9, 0x4a, 0x24, 0xbe,
     60 	0x8a, 0xb1, 0x19, 0xe3, 0x98, 0x72, 0x2f, 0x08, 0x29, 0x06, 0x6a, 0xbc,
     61 	0x9b, 0x0f, 0xa3, 0x83, 0x22, 0xe4, 0xf1, 0x8b, 0xcf, 0x56, 0xc5, 0x4e,
     62 	0x1f, 0x6e, 0xdf, 0xdd, 0x9e, 0xb3, 0x14, 0xe2, 0x59, 0xe8, 0x04, 0xd8,
     63 	0x4b, 0xd6, 0xed, 0x32, 0xfc, 0x3a, 0x07, 0xbb, 0xe1, 0xe4, 0xee, 0x6d,
     64 	0xb3, 0x23, 0x63, 0xa8, 0x8e, 0xc5, 0x97, 0xb9, 0xb2, 0x89, 0x68, 0x6a,
     65 	0x75, 0x13, 0x1e, 0xca, 0x8d, 0x62, 0x6d, 0x4c, 0xf1, 0x8f, 0x93, 0xd2,
     66 	0xac, 0x96, 0xf7, 0xd6, 0xde, 0xf7, 0xb2, 0x2c, 0xf8, 0x7d, 0x54, 0x31,
     67 	0x34, 0xe3, 0x50, 0xd5, 0x55, 0xc8, 0xa8, 0xce, 0x45, 0x78, 0xf4, 0xfc,
     68 	0xf4, 0x1d, 0x7d, 0xde, 0x9f, 0xb7, 0x7d, 0xc3, 0x1b, 0xfd, 0xb4, 0x5a,
     69 	0x1f, 0x7d, 0x69, 0x55, 0x5c, 0x76, 0x75, 0xd0, 0x14, 0x42, 0x28, 0xf9,
     70 	0x6b, 0xd0, 0x35, 0x9b, 0xe3, 0x9c, 0x64, 0xd0, 0x0d, 0x16, 0x5f, 0x66,
     71 	0x41, 0xe9, 0x84, 0x27, 0x60, 0xe6, 0x9e, 0x24, 0x7e, 0x89, 0xc5, 0x99,
     72 	0x4e, 0x3e, 0xfd, 0x6b, 0xcc, 0xa9, 0x99, 0xbe, 0x04, 0x9f, 0xd0, 0x8a,
     73 	0x97, 0x05, 0x36, 0x82, 0xc9, 0x00, 0x85, 0x1a, 0x1e, 0x6b, 0x02, 0x8e,
     74 	0xab, 0x5b, 0xfd, 0x52, 0x65, 0x7c, 0x95, 0x57, 0x35, 0xcc, 0x05, 0xe8,
     75 	0x82, 0x80, 0x42, 0x65, 0x1d, 0x04, 0xdc, 0x1c, 0x45, 0xf0, 0x91, 0x3a,
     76 	0x8c, 0x87, 0x44, 0xa3, 0x7b, 0x15, 0xe8, 0xfd, 0xb4, 0xb6, 0x56, 0x53,
     77 	0xaa, 0x5f, 0xdb, 0x3f, 0x46, 0x86, 0xb4, 0x97, 0xfb, 0x12, 0x73, 0xe0,
     78 	0xfc, 0x92, 0x0c, 0xcf, 0x80, 0x9f, 0x3b, 0x8b, 0x8a, 0xd0, 0x0e, 0x93,
     79 	0xd7, 0xcf, 0x87, 0xb7, 0xe2, 0x85, 0x83, 0x22, 0x18, 0x36, 0x31, 0xed,
     80 	0x5a, 0x75, 0xc0, 0xe3, 0x54, 0xcd, 0xf4, 0x55, 0xbd, 0xdc, 0xdc, 0x63,
     81 	0x9b, 0x48, 0x62, 0x6c, 0x59, 0x6d, 0xff, 0xe1, 0x23, 0xa1, 0x1f, 0xd2,
     82 	0xbd, 0x54, 0x90, 0xda, 0x3f, 0x1a, 0x02, 0xdd, 0xbd, 0x63, 0x46, 0x86,
     83 	0x7e, 0xda, 0x6c, 0x5e, 0xed, 0x18, 0x8f, 0x55, 0x70, 0xce, 0xba, 0x8f,
     84 	0xab, 0x25, 0xb4, 0x3a, 0xa2, 0x9d, 0xca, 0x6e, 0xd2, 0xb6, 0xb3, 0x8b,
     85 	0xb2, 0xcf, 0x4e, 0xa2, 0x84, 0x7e, 0xdf, 0xf0, 0x46, 0x28, 0x23, 0x90,
     86 	0x88, 0x0d, 0x12, 0x85, 0x39, 0xbc, 0xfc, 0x1d, 0x51, 0xee, 0x96, 0xca,
     87 	0x8b, 0x60, 0x99, 0xba, 0xa0, 0x77, 0x63, 0x05, 0xd7, 0xa4, 0xc6, 0x03,
     88 	0xc0, 0x1d, 0x6f, 0x69, 0xbe, 0x4b, 0x4a, 0xaf, 0xeb, 0x2b, 0xc8, 0xc6,
     89 ];
     90 
     91 const sig384: [_]u8 = [
     92 	0x0b, 0xed, 0x44, 0xc2, 0xb6, 0x97, 0xe0, 0xe2, 0x02, 0xb3, 0x66, 0x4f,
     93 	0x5b, 0x8d, 0xf0, 0xb8, 0x82, 0x0f, 0x4f, 0x28, 0x6d, 0xd4, 0x81, 0xb6,
     94 	0x24, 0x1f, 0x66, 0x1a, 0xa9, 0xa1, 0x8c, 0x4d, 0xc0, 0x11, 0x36, 0x03,
     95 	0xf9, 0x2d, 0x35, 0x6e, 0xc8, 0xeb, 0x95, 0x77, 0x86, 0xcf, 0xae, 0x4d,
     96 	0x40, 0xf5, 0xed, 0xef, 0x9b, 0x9c, 0x24, 0x2b, 0x89, 0x04, 0x89, 0x46,
     97 	0x2c, 0xbd, 0xea, 0x0a, 0xa9, 0xba, 0x50, 0x89, 0xc8, 0x52, 0x33, 0x63,
     98 	0xe4, 0xbf, 0x26, 0x4a, 0x57, 0x82, 0xc7, 0xc8, 0x5b, 0x9e, 0x64, 0x94,
     99 	0x1e, 0xe5, 0x26, 0x8a, 0xde, 0x6b, 0x63, 0xe1, 0x3f, 0xd8, 0x18, 0xf9,
    100 	0xcc, 0xe5, 0x33, 0x0d, 0x98, 0x41, 0xc3, 0xb5, 0x9a, 0x9c, 0x90, 0xb7,
    101 	0xe8, 0xc4, 0x68, 0xa0, 0xb8, 0x8d, 0x22, 0x5f, 0x5a, 0xe4, 0x53, 0xbf,
    102 	0x82, 0x08, 0x6e, 0x5f, 0xe1, 0xa5, 0xeb, 0x23, 0x8a, 0xc9, 0xe3, 0xeb,
    103 	0x6b, 0xd1, 0x6d, 0x95, 0x64, 0xc0, 0x25, 0x37, 0xc9, 0xb4, 0x14, 0x85,
    104 	0xa9, 0x7e, 0x44, 0xbc, 0x15, 0x56, 0xdb, 0x03, 0xac, 0x4d, 0x19, 0x61,
    105 	0x24, 0x5a, 0xc3, 0x48, 0x34, 0x72, 0xff, 0xc6, 0x97, 0xee, 0xf8, 0xf7,
    106 	0xdb, 0x07, 0xce, 0x47, 0x61, 0x53, 0x40, 0xe7, 0xf4, 0x2b, 0xca, 0xa0,
    107 	0xcc, 0xd6, 0xd8, 0x46, 0x5b, 0x88, 0xd9, 0xf0, 0xd9, 0x01, 0x87, 0x85,
    108 	0x33, 0x6b, 0x34, 0xb8, 0x34, 0xc8, 0x50, 0x86, 0x1f, 0xbe, 0xf9, 0xca,
    109 	0x07, 0x13, 0x2b, 0x31, 0x20, 0x92, 0xb2, 0xec, 0x31, 0xf0, 0xd1, 0x45,
    110 	0xab, 0x8c, 0xaa, 0x19, 0xb6, 0x81, 0x98, 0x31, 0x74, 0xd2, 0x96, 0x4e,
    111 	0x6a, 0xac, 0x90, 0xbe, 0xfe, 0xb7, 0xbb, 0x56, 0x3b, 0x72, 0x68, 0x0e,
    112 	0xc4, 0xef, 0x63, 0xc9, 0xfe, 0xe8, 0xa2, 0xf6, 0x92, 0x82, 0x05, 0x24,
    113 	0xf2, 0x52, 0xb0, 0x5a, 0x90, 0xdf, 0x04, 0xff, 0x6c, 0xb0, 0x79, 0x80,
    114 	0x28, 0xb0, 0x64, 0x08, 0x14, 0x93, 0x12, 0x02, 0x13, 0xd3, 0x6d, 0x8c,
    115 	0x9c, 0xfe, 0x42, 0x89, 0xcd, 0xc5, 0x94, 0x9f, 0x46, 0x72, 0xda, 0x49,
    116 	0x4d, 0xd9, 0xa6, 0x97, 0x21, 0x80, 0xa2, 0xfa, 0x57, 0x79, 0xd0, 0xc6,
    117 	0x83, 0x30, 0x29, 0x26, 0x09, 0x81, 0xba, 0x17, 0x60, 0x06, 0x31, 0x21,
    118 	0x6f, 0xfc, 0xf6, 0x53, 0x93, 0xe9, 0x7f, 0xe2, 0x64, 0x56, 0xd5, 0xf5,
    119 	0x11, 0x4f, 0x8b, 0xe1, 0xce, 0x3f, 0x41, 0x54, 0xf4, 0x5f, 0x08, 0xbc,
    120 	0xfd, 0x13, 0x21, 0x62, 0x99, 0x4a, 0x4e, 0x8c, 0x14, 0xd2, 0x80, 0xf0,
    121 	0x18, 0x9c, 0xbf, 0x3a, 0xb4, 0x80, 0x5b, 0x3d, 0x28, 0xa5, 0xbc, 0x12,
    122 	0x96, 0x9d, 0xa9, 0x92, 0x01, 0xbe, 0x62, 0xbb, 0xf6, 0x1f, 0x24, 0x37,
    123 	0xfa, 0xa2, 0xe4, 0x73, 0x65, 0x27, 0x0b, 0xc6, 0x95, 0x86, 0x2e, 0x46,
    124 ];
    125 
    126 const sig512: [_]u8 = [
    127 	0x6e, 0xb5, 0x5f, 0xbd, 0x48, 0x09, 0x08, 0x7c, 0x01, 0xb3, 0x74, 0x26,
    128 	0x73, 0x9d, 0x3e, 0xd5, 0x08, 0x7d, 0xe8, 0x11, 0x01, 0x21, 0x31, 0x11,
    129 	0x91, 0x34, 0x5b, 0xe5, 0x6c, 0x37, 0x79, 0x7b, 0xdb, 0x75, 0x16, 0x62,
    130 	0x0e, 0x7d, 0x1d, 0xd1, 0x04, 0x45, 0xbc, 0xa9, 0x79, 0xd0, 0xb1, 0x1d,
    131 	0x1e, 0x20, 0x65, 0x37, 0x92, 0x90, 0xa8, 0xd3, 0x5f, 0x07, 0x24, 0x54,
    132 	0x53, 0x97, 0x69, 0x84, 0xe2, 0xbb, 0xc0, 0xb5, 0x82, 0x4f, 0x29, 0xac,
    133 	0xc9, 0x07, 0xa7, 0x75, 0x08, 0x1c, 0x0c, 0x72, 0x9f, 0x35, 0x1b, 0x75,
    134 	0xb2, 0x79, 0x3f, 0x41, 0xa5, 0xcb, 0x9d, 0x69, 0x02, 0xa8, 0x08, 0xfe,
    135 	0x11, 0x19, 0x2f, 0xc2, 0xdb, 0x0e, 0xa6, 0xe0, 0xc4, 0x44, 0x33, 0xd6,
    136 	0xad, 0x59, 0x11, 0xa7, 0x38, 0xc0, 0xe7, 0x37, 0x21, 0xa8, 0x13, 0x96,
    137 	0xe9, 0x63, 0x25, 0xd9, 0x2e, 0xbf, 0x10, 0x59, 0x49, 0xdd, 0xc0, 0x55,
    138 	0xeb, 0x6d, 0xbe, 0x0a, 0x1e, 0xe2, 0x62, 0xce, 0x53, 0x2e, 0xaa, 0xed,
    139 	0xe5, 0x7e, 0xf7, 0x1b, 0xbb, 0x09, 0x75, 0x5e, 0x5f, 0xf9, 0x78, 0x12,
    140 	0x51, 0xa4, 0x63, 0x52, 0xa4, 0xba, 0x45, 0xbc, 0x48, 0x89, 0xb2, 0x73,
    141 	0xb4, 0xa5, 0x25, 0xd3, 0x1a, 0xd5, 0x9d, 0xff, 0x4e, 0xba, 0xd0, 0xb0,
    142 	0xb5, 0x21, 0x11, 0x25, 0x4d, 0x84, 0x90, 0x6e, 0xcd, 0x68, 0xd6, 0xd7,
    143 	0x39, 0xf7, 0x03, 0xb5, 0x7e, 0x78, 0x7e, 0x33, 0x2c, 0x7f, 0x34, 0x8f,
    144 	0x6f, 0xb2, 0x24, 0xe0, 0x5f, 0xd6, 0x18, 0x42, 0x4d, 0xb4, 0x5b, 0xe5,
    145 	0xc6, 0x92, 0xde, 0x54, 0x37, 0x69, 0x36, 0x7d, 0xe0, 0x0b, 0xa2, 0x6a,
    146 	0xb7, 0x41, 0xf4, 0x23, 0x09, 0x7f, 0x26, 0x64, 0xff, 0x10, 0x8a, 0x28,
    147 	0x34, 0xca, 0x08, 0x81, 0xf5, 0x38, 0x58, 0x46, 0xd2, 0xc0, 0x1c, 0x35,
    148 	0x31, 0x69, 0xcc, 0x4a, 0xed, 0x04, 0x22, 0x06, 0xbf, 0x79, 0x62, 0x0e,
    149 	0x43, 0x5e, 0x90, 0xf3, 0x95, 0x6b, 0x6e, 0xc3, 0x80, 0x9c, 0x63, 0xd1,
    150 	0xf7, 0xf2, 0x9f, 0x83, 0xb2, 0x09, 0x08, 0xcf, 0xb3, 0x87, 0x79, 0xc6,
    151 	0x24, 0xe6, 0x98, 0x58, 0xda, 0xdc, 0x0c, 0x67, 0x4c, 0x1f, 0xe7, 0xc3,
    152 	0x26, 0xec, 0xdd, 0x7e, 0x91, 0xb0, 0x31, 0x99, 0x5c, 0x93, 0x52, 0x17,
    153 	0xa2, 0x0f, 0xb1, 0xfb, 0x09, 0xd2, 0xa9, 0xe5, 0xdf, 0x1e, 0x5c, 0xa8,
    154 	0xf5, 0x0c, 0x20, 0xc3, 0xe3, 0x07, 0x32, 0x1b, 0x42, 0xc1, 0x58, 0xb2,
    155 	0x1c, 0x52, 0x7d, 0x56, 0xf8, 0x0c, 0xad, 0x03, 0xf5, 0x40, 0x07, 0x9c,
    156 	0xf4, 0x41, 0xf5, 0x54, 0xed, 0x66, 0x11, 0xd6, 0x98, 0xa4, 0x32, 0xd2,
    157 	0x94, 0x02, 0x74, 0xa9, 0xe1, 0x3a, 0x61, 0x18, 0x37, 0x54, 0xce, 0x03,
    158 	0x17, 0xc9, 0xc9, 0x99, 0x22, 0xd7, 0x3f, 0x71, 0x7f, 0xf5, 0x8d, 0xa3,
    159 ];
    160 
    161 const sig512_224: [_]u8 = [
    162 	0x65, 0xda, 0xf7, 0x42, 0x16, 0xe9, 0xcb, 0xc0, 0xed, 0x1e, 0xb7, 0xf1,
    163 	0x18, 0xab, 0x30, 0xf4, 0xe9, 0xf3, 0x4c, 0x1f, 0x8f, 0x94, 0x61, 0x79,
    164 	0xe1, 0x89, 0x89, 0xbb, 0x6d, 0x26, 0xcb, 0xfc, 0xaf, 0x99, 0xdc, 0x6b,
    165 	0x16, 0x4c, 0x51, 0x4f, 0x49, 0xb0, 0xd8, 0x98, 0x89, 0x95, 0x10, 0x6f,
    166 	0xa2, 0x50, 0x6e, 0x04, 0xaa, 0x98, 0xd7, 0x63, 0x91, 0x21, 0x8f, 0x5a,
    167 	0xd5, 0xd1, 0x9c, 0x31, 0xe2, 0x0c, 0xd1, 0xb1, 0xf8, 0xf5, 0x06, 0x75,
    168 	0x50, 0x33, 0x31, 0x49, 0xa4, 0xac, 0x87, 0x75, 0x1b, 0x03, 0x12, 0x27,
    169 	0x23, 0xbf, 0xe5, 0xe5, 0xcf, 0xa6, 0x33, 0xeb, 0xa3, 0x20, 0xbd, 0xc7,
    170 	0x21, 0x89, 0x4a, 0x66, 0x8a, 0x0d, 0xe4, 0x29, 0x7f, 0x39, 0xe1, 0x21,
    171 	0x7e, 0x2d, 0x23, 0x26, 0xe0, 0xae, 0xc9, 0xb7, 0xb6, 0xce, 0x85, 0x2d,
    172 	0x9e, 0x98, 0xc0, 0x02, 0x6c, 0x4e, 0x81, 0xcf, 0x4f, 0xea, 0x85, 0x66,
    173 	0xae, 0x4a, 0xca, 0xf9, 0x48, 0x35, 0x0c, 0xb4, 0x33, 0x30, 0xb9, 0x60,
    174 	0xc3, 0x9b, 0xb7, 0x02, 0x81, 0x02, 0xb2, 0x85, 0xcf, 0x64, 0x41, 0xa9,
    175 	0xc9, 0xf1, 0x71, 0x04, 0xef, 0xe1, 0x27, 0xbd, 0x8d, 0xd6, 0x16, 0xb3,
    176 	0xfc, 0x2e, 0xf3, 0x5b, 0xfa, 0xb1, 0xa3, 0xfd, 0x22, 0x58, 0xda, 0xaf,
    177 	0x0c, 0x3b, 0xf4, 0x9c, 0xa9, 0x53, 0x0c, 0x96, 0x2f, 0x73, 0x9f, 0x74,
    178 	0xb3, 0x03, 0xf6, 0xb6, 0x4e, 0xcb, 0x40, 0xed, 0xb3, 0x1b, 0x1c, 0x53,
    179 	0x19, 0xf7, 0x78, 0xb0, 0x59, 0x05, 0xd5, 0x1b, 0x5e, 0xb9, 0xaf, 0x23,
    180 	0xdd, 0xa9, 0xc4, 0x2d, 0x6f, 0x09, 0x67, 0xcb, 0x5d, 0x9e, 0x03, 0xfb,
    181 	0xe6, 0x70, 0x72, 0xef, 0x62, 0xb8, 0x50, 0xad, 0x70, 0xb1, 0x34, 0xfd,
    182 	0x92, 0x0f, 0xb1, 0xfd, 0x8a, 0x37, 0x63, 0x93, 0xa2, 0x9b, 0x2c, 0x9b,
    183 	0x62, 0xe6, 0x95, 0x3a, 0xfb, 0x44, 0x4c, 0xf5, 0x96, 0x2b, 0x9f, 0x7a,
    184 	0x6f, 0xae, 0xc4, 0xa5, 0xe4, 0x23, 0x3b, 0x06, 0xf5, 0x95, 0x89, 0xa6,
    185 	0x15, 0xb1, 0xd5, 0xa3, 0xdd, 0x2c, 0x17, 0xf5, 0x60, 0x5d, 0x09, 0x69,
    186 	0x42, 0x88, 0xe7, 0x21, 0x60, 0x79, 0xe9, 0x69, 0x9d, 0x12, 0x2e, 0x6a,
    187 	0xdf, 0x51, 0x45, 0x54, 0x91, 0x54, 0x17, 0xe7, 0x6c, 0x8c, 0xbf, 0xe3,
    188 	0x69, 0xc2, 0xfa, 0xb4, 0x7b, 0x72, 0xda, 0x48, 0xe4, 0xd1, 0xce, 0x86,
    189 	0x8f, 0x17, 0x5d, 0x18, 0x21, 0x72, 0x28, 0x8a, 0x78, 0xca, 0xa1, 0x90,
    190 	0x6b, 0x6d, 0xc0, 0x39, 0xb3, 0xe9, 0x71, 0x65, 0xe8, 0xbb, 0x19, 0xf4,
    191 	0x8b, 0x59, 0xc2, 0x9e, 0x7b, 0xa3, 0xf2, 0xcb, 0x0d, 0xa0, 0xb4, 0x32,
    192 	0xe2, 0xdb, 0x72, 0x5c, 0x7f, 0xe2, 0x32, 0x77, 0x62, 0xf1, 0xb9, 0x34,
    193 	0xe9, 0x95, 0x8d, 0x76, 0xa4, 0xf2, 0xd2, 0x31, 0x46, 0xc1, 0xf9, 0xdb,
    194 ];
    195 
    196 const sig512_256: [_]u8 = [
    197 	0xb9, 0x33, 0xe4, 0x78, 0x0f, 0x91, 0xa3, 0xe4, 0x2c, 0x34, 0x9a, 0xfc,
    198 	0x00, 0xba, 0x37, 0x8e, 0x1f, 0x94, 0xe4, 0xf2, 0xae, 0x75, 0x96, 0x9f,
    199 	0xe1, 0x9c, 0xef, 0xf9, 0x72, 0x50, 0x21, 0x3b, 0xe6, 0xef, 0xa5, 0x3e,
    200 	0x04, 0x9e, 0x75, 0x25, 0x1a, 0x2c, 0xa1, 0x74, 0x26, 0x74, 0x20, 0x57,
    201 	0x2c, 0xda, 0x83, 0x1f, 0x21, 0xb0, 0x07, 0x0a, 0x88, 0xd3, 0x1d, 0x0c,
    202 	0x59, 0xef, 0x93, 0x1d, 0x38, 0xe6, 0xe8, 0x77, 0x3a, 0x70, 0xad, 0xb2,
    203 	0xcd, 0x9e, 0x3b, 0xf0, 0x48, 0xfd, 0x49, 0xe7, 0x06, 0x8e, 0x6d, 0x16,
    204 	0x01, 0x44, 0x8f, 0xbd, 0x74, 0x96, 0xae, 0xc6, 0x6f, 0x03, 0x7f, 0xc2,
    205 	0xb1, 0x0c, 0x00, 0x45, 0xbe, 0x14, 0x1a, 0xdc, 0xa2, 0xe8, 0x61, 0xaf,
    206 	0x03, 0x39, 0x5a, 0xa9, 0x6c, 0xf2, 0xa7, 0x31, 0x95, 0x91, 0x4f, 0xf2,
    207 	0xff, 0x93, 0x03, 0xac, 0x8e, 0xe7, 0x1c, 0xd7, 0xae, 0x71, 0x9a, 0x5d,
    208 	0x0e, 0xb6, 0xed, 0x99, 0x24, 0x8c, 0xec, 0x95, 0x9e, 0x98, 0xf6, 0x04,
    209 	0xb8, 0xa9, 0x36, 0x64, 0xbe, 0xdd, 0x3d, 0x9f, 0x59, 0xed, 0x7d, 0x51,
    210 	0x5b, 0x1a, 0xb5, 0x68, 0x00, 0xa1, 0x5f, 0x0e, 0xdb, 0xb1, 0xd5, 0x43,
    211 	0x4f, 0xd7, 0x2e, 0xc7, 0x61, 0x86, 0xdb, 0x21, 0xaf, 0xa7, 0xd3, 0x0f,
    212 	0xb6, 0xa2, 0x59, 0x34, 0x86, 0xeb, 0xe6, 0x2e, 0x44, 0xb3, 0x2c, 0xea,
    213 	0x1c, 0x47, 0x7c, 0x81, 0x54, 0xba, 0x4a, 0x3a, 0x89, 0x63, 0x1e, 0x2f,
    214 	0x10, 0x2b, 0x96, 0xd2, 0x54, 0x76, 0xa3, 0xd8, 0x2c, 0x41, 0xb8, 0xaa,
    215 	0xd0, 0x35, 0xf0, 0x00, 0xf6, 0xba, 0x82, 0x4d, 0xe4, 0xe7, 0x5a, 0xfc,
    216 	0x2e, 0xc6, 0x03, 0x2e, 0x9e, 0x90, 0x0c, 0x37, 0xa8, 0xff, 0x87, 0xa7,
    217 	0x78, 0x2f, 0x68, 0xd2, 0x85, 0xa8, 0xf2, 0x93, 0x88, 0x2a, 0x90, 0x03,
    218 	0xe1, 0x4a, 0x2e, 0x58, 0x63, 0x92, 0x21, 0xf2, 0x8c, 0x3d, 0xdd, 0x49,
    219 	0xc1, 0x0e, 0x15, 0x1b, 0xcf, 0x21, 0xd5, 0x0d, 0x24, 0xba, 0xd6, 0x29,
    220 	0xdb, 0xb3, 0x53, 0xfc, 0x56, 0xa9, 0x55, 0xb6, 0x1e, 0x8d, 0xd5, 0xd7,
    221 	0x16, 0x0c, 0x65, 0x53, 0xc7, 0xda, 0xc7, 0x8b, 0x35, 0x99, 0x38, 0x80,
    222 	0xa8, 0xe7, 0x5e, 0x57, 0x60, 0xad, 0x24, 0xe6, 0x0c, 0x4c, 0xa3, 0xbf,
    223 	0xe5, 0x79, 0x9c, 0x1b, 0xa2, 0x1f, 0x6c, 0xf4, 0x4b, 0x50, 0x36, 0x15,
    224 	0xf7, 0x9b, 0xab, 0x17, 0x8f, 0x15, 0x1f, 0x5b, 0x93, 0x67, 0x56, 0x70,
    225 	0x5c, 0x5b, 0x59, 0xef, 0x1b, 0x41, 0xf9, 0x36, 0xc5, 0x6f, 0x49, 0x1e,
    226 	0x2f, 0x99, 0xdd, 0x13, 0xb6, 0xd1, 0x2b, 0xb9, 0x68, 0x36, 0xbf, 0x02,
    227 	0xd6, 0x27, 0x6f, 0xeb, 0x83, 0x8a, 0x77, 0x12, 0xf7, 0x07, 0xd8, 0x3f,
    228 	0x60, 0x57, 0x5b, 0x24, 0x73, 0x64, 0x85, 0x90, 0xf0, 0xbd, 0x76, 0xcd,
    229 ];
    230 
    231 @test fn pkcs1() void = {
    232 	let pk = sign3072.priv;
    233 	let priv: [PRIVKEYSIZE]u8 = [0...];
    234 	privkey_init(priv, sign3072.priv)!;
    235 
    236 	let pub: [PUBKEYSIZE]u8 = [0...];
    237 	pubkey_init(pub, sign3072.pub)!;
    238 
    239 	assertpkcs1(priv, pub, msg, sig1, pkcs1_hashalgo::SHA1);
    240 	assertpkcs1(priv, pub, msg, sig256, pkcs1_hashalgo::SHA256);
    241 	assertpkcs1(priv, pub, msg, sig384, pkcs1_hashalgo::SHA384);
    242 	assertpkcs1(priv, pub, msg, sig512, pkcs1_hashalgo::SHA512);
    243 	assertpkcs1(priv, pub, msg, sig512_224, pkcs1_hashalgo::SHA512_224);
    244 	assertpkcs1(priv, pub, msg, sig512_256, pkcs1_hashalgo::SHA512_256);
    245 };
    246 
    247 fn assertpkcs1(
    248 	priv: []u8,
    249 	pub: []u8,
    250 	msg: []u8,
    251 	sig: []u8,
    252 	algo: pkcs1_hashalgo
    253 ) void = {
    254 	let nsig: []u8 = alloc([0...], len(sig));
    255 	defer free(nsig);
    256 
    257 	let msghash = pkcs1_hash(msg, algo);
    258 	defer free(msghash);
    259 
    260 	pkcs1_sign(priv, msghash, nsig, algo, pkcs1_signbuf)!;
    261 	assert(bytes::equal(nsig, sig));
    262 
    263 	pkcs1_verify(pub, msghash, sig, algo, pkcs1_verifybuf)!;
    264 
    265 	const tmp = msghash[0];
    266 	msghash[0] += 1;
    267 	assert(pkcs1_verify(pub, msghash, sig, algo, pkcs1_verifybuf) is error);
    268 
    269 	msghash[0] = tmp;
    270 	nsig[0] += 1;
    271 	assert(pkcs1_verify(pub, msghash, nsig, algo, pkcs1_verifybuf) is error);
    272 };
    273 
    274 fn pkcs1_hash(msg: []u8, algo: pkcs1_hashalgo) []u8 = {
    275 	let h: *hash::hash = switch (algo) {
    276 	case pkcs1_hashalgo::SHA1 =>
    277 		yield &sha1::sha1();
    278 	case pkcs1_hashalgo::SHA256 =>
    279 		yield &sha256::sha256();
    280 	case pkcs1_hashalgo::SHA384 =>
    281 		yield &sha512::sha384();
    282 	case pkcs1_hashalgo::SHA512 =>
    283 		yield &sha512::sha512();
    284 	case pkcs1_hashalgo::SHA512_224 =>
    285 		yield &sha512::sha512_224();
    286 	case pkcs1_hashalgo::SHA512_256 =>
    287 		yield &sha512::sha512_256();
    288 	case =>
    289 		abort("unreachable");
    290 	};
    291 	defer hash::close(h);
    292 	let out: []u8 = alloc([0...], hash::sz(h));
    293 
    294 	io::writeall(h, msg)!;
    295 	hash::sum(h, out);
    296 	return out;
    297 };