Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 1 | /* Copyright lowRISC contributors. */ |
| 2 | /* Licensed under the Apache License, Version 2.0, see LICENSE for details. */ |
| 3 | /* SPDX-License-Identifier: Apache-2.0 */ |
| 4 | |
| 5 | |
| 6 | .text |
| 7 | |
| 8 | /** |
| 9 | * Standalone RSA 1024 decrypt |
| 10 | * |
| 11 | * Uses OTBN modexp bignum lib to decrypt the message from the .data segment |
| 12 | * in this file with the private key contained in .data segment of this file. |
| 13 | * |
| 14 | * Copies the decrypted message to wide registers for comparison (starting at |
| 15 | * w0). See comment at the end of the file for expected values. |
| 16 | */ |
Philipp Wagner | cab8303 | 2020-11-04 15:28:12 +0000 | [diff] [blame] | 17 | run_rsa_1024_dec: |
Felix Miller | 1f37185 | 2020-10-31 22:22:32 +0100 | [diff] [blame] | 18 | jal x1, modload |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 19 | jal x1, modexp |
| 20 | /* pointer to out buffer */ |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 21 | lw x21, 28(x0) |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 22 | |
| 23 | /* copy all limbs of result to wide reg file */ |
| 24 | li x8, 0 |
| 25 | loop x30, 2 |
| 26 | bn.lid x8, 0(x21++) |
| 27 | addi x8, x8, 1 |
| 28 | |
| 29 | ecall |
| 30 | |
| 31 | |
| 32 | .data |
| 33 | |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 34 | /* reserved */ |
| 35 | .word 0x00000000 |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 36 | |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 37 | /* number of limbs (N) */ |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 38 | .word 0x00000004 |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 39 | |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 40 | /* pointer to m0' (dptr_m0d) */ |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 41 | .word 0x00000280 |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 42 | |
| 43 | /* pointer to RR (dptr_rr) */ |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 44 | .word 0x000002c0 |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 45 | |
| 46 | /* load pointer to modulus (dptr_m) */ |
| 47 | .word 0x00000080 |
| 48 | |
| 49 | /* pointer to base bignum buffer (dptr_in) */ |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 50 | .word 0x000004c0 |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 51 | |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 52 | /* pointer to exponent buffer (dptr_exp) */ |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 53 | .word 0x000006c0 |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 54 | |
| 55 | /* pointer to out buffer (dptr_out) */ |
| 56 | .word 0x000008c0 |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 57 | |
| 58 | |
Felix Miller | 8f31e6f | 2020-11-02 01:56:43 +0100 | [diff] [blame] | 59 | /* Modulus */ |
| 60 | /* skip to 128 */ |
| 61 | .skip 96 |
| 62 | |
Felix Miller | 50c6c51 | 2020-10-15 14:06:08 +0200 | [diff] [blame] | 63 | .word 0xc28cf49f |
| 64 | .word 0xb6e64c3b |
| 65 | .word 0xa21417f1 |
| 66 | .word 0x34ab89fe |
| 67 | .word 0xe4d4c752 |
| 68 | .word 0xe9289a03 |
| 69 | .word 0xc8aa371c |
| 70 | .word 0xafb68c05 |
| 71 | |
| 72 | .word 0x893c882e |
| 73 | .word 0xa62c908d |
| 74 | .word 0xd23f4ebf |
| 75 | .word 0xea5bb198 |
| 76 | .word 0xdb6f076f |
| 77 | .word 0xcfcc4b48 |
| 78 | .word 0x75a24aa4 |
| 79 | .word 0x7bda03fc |
| 80 | |
| 81 | .word 0xcb5adf60 |
| 82 | .word 0xbc7c20bc |
| 83 | .word 0x8ea4f2fe |
| 84 | .word 0x3ba5d46d |
| 85 | .word 0x21536a4e |
| 86 | .word 0x7f292995 |
| 87 | .word 0xaafd0e56 |
| 88 | .word 0xc8033b94 |
| 89 | |
| 90 | .word 0x127ca9e8 |
| 91 | .word 0xa3998c2e |
| 92 | .word 0xecf3ecf6 |
| 93 | .word 0xc39b1e20 |
| 94 | .word 0xdc59f4e7 |
| 95 | .word 0x5affc57c |
| 96 | .word 0x0a4536b4 |
| 97 | .word 0x962be299 |
| 98 | |
| 99 | |
| 100 | /* encrypted message */ |
| 101 | /* skip to 1216 */ |
| 102 | .skip 960 |
| 103 | |
| 104 | .word 0xe0e14a9b |
| 105 | .word 0x7ae96741 |
| 106 | .word 0x4a430036 |
| 107 | .word 0xcda13a47 |
| 108 | .word 0x79524410 |
| 109 | .word 0x3810cd51 |
| 110 | .word 0x3b47425f |
| 111 | .word 0x686f3abe |
| 112 | |
| 113 | .word 0x91dff899 |
| 114 | .word 0xbfa8b284 |
| 115 | .word 0x0539e396 |
| 116 | .word 0xa66cf53c |
| 117 | .word 0xbcdc315a |
| 118 | .word 0x0d595811 |
| 119 | .word 0x0a522e08 |
| 120 | .word 0x5b9dce33 |
| 121 | |
| 122 | .word 0x6fde2d48 |
| 123 | .word 0x587a618e |
| 124 | .word 0x6b4c0c56 |
| 125 | .word 0x4affcc62 |
| 126 | .word 0x6a88ead2 |
| 127 | .word 0x991f39d0 |
| 128 | .word 0x39f88b9a |
| 129 | .word 0x3c0d6626 |
| 130 | |
| 131 | .word 0xa3fe6181 |
| 132 | .word 0x82f3f1f6 |
| 133 | .word 0x43f4ed0b |
| 134 | .word 0x938bfd7b |
| 135 | .word 0x60de8b63 |
| 136 | .word 0x8ade6cc0 |
| 137 | .word 0x91f560d7 |
| 138 | .word 0x35f506d1 |
| 139 | |
| 140 | |
| 141 | /* private exponent */ |
| 142 | /* skip to 1728 */ |
| 143 | .skip 384 |
| 144 | |
| 145 | .word 0x93a8cd95 |
| 146 | .word 0x24a2614b |
| 147 | .word 0xeeb788b3 |
| 148 | .word 0x6dfc48e4 |
| 149 | .word 0xca97cdc4 |
| 150 | .word 0x41146c79 |
| 151 | .word 0xf4ca744b |
| 152 | .word 0xc386c827 |
| 153 | |
| 154 | .word 0xd9ddaef3 |
| 155 | .word 0xae51440f |
| 156 | .word 0x9741739d |
| 157 | .word 0x9ebad71b |
| 158 | .word 0x9a7a2bfd |
| 159 | .word 0xfbd58848 |
| 160 | .word 0x13464f06 |
| 161 | .word 0x17f60ed9 |
| 162 | |
| 163 | .word 0x1d63a0b9 |
| 164 | .word 0x581ccd6c |
| 165 | .word 0x951579d6 |
| 166 | .word 0x35a9ec64 |
| 167 | .word 0xc3a08e32 |
| 168 | .word 0xdd2f62e8 |
| 169 | .word 0xc3739e4a |
| 170 | .word 0x01ca5c4e |
| 171 | |
| 172 | .word 0x3a107e7d |
| 173 | .word 0xf9dacc79 |
| 174 | .word 0x49ecbe20 |
| 175 | .word 0x5d21e910 |
| 176 | .word 0x9550ecb5 |
| 177 | .word 0x511778ce |
| 178 | .word 0x42209f7b |
| 179 | .word 0x41b468dc |
| 180 | |
| 181 | /* Expected decrypted Message in wide register file: |
| 182 | w0 = 0x656e637279707420616e642064656372797074207468697320666f72206d653f |
| 183 | w1 = 0x0000000000000000000048656c6c6f206269676e756d2c2063616e20796f7520 |
| 184 | w2 = 0x0000000000000000000000000000000000000000000000000000000000000000 |
| 185 | w3 = 0x0000000000000000000000000000000000000000000000000000000000000000 |
| 186 | */ |