|  | 
| 16 | 16 | 
 | 
| 17 | 17 | #include "random.h" | 
| 18 | 18 | 
 | 
|  | 19 | +void secure_erase(void *buf, size_t size) { | 
|  | 20 | +   volatile char *vbuf = (volatile char *)buf; | 
|  | 21 | +   size_t i; | 
|  | 22 | +    for (i = 0; i < size; ++i) { | 
|  | 23 | +        vbuf[i] = 0; | 
|  | 24 | +    } | 
|  | 25 | +} | 
| 19 | 26 | 
 | 
| 20 | 27 | int main(void) { | 
| 21 |  | -    volatile unsigned char seckey1[32]; | 
| 22 |  | -    volatile unsigned char seckey2[32]; | 
|  | 28 | +    unsigned char seckey1[32]; | 
|  | 29 | +    unsigned char seckey2[32]; | 
| 23 | 30 |     unsigned char compressed_pubkey1[33]; | 
| 24 | 31 |     unsigned char compressed_pubkey2[33]; | 
| 25 |  | -    volatile unsigned char shared_secret1[32]; | 
| 26 |  | -    volatile unsigned char shared_secret2[32]; | 
|  | 32 | +    unsigned char shared_secret1[32]; | 
|  | 33 | +    unsigned char shared_secret2[32]; | 
| 27 | 34 |     unsigned char randomize[32]; | 
| 28 | 35 |     int return_val; | 
| 29 | 36 |     size_t len; | 
| @@ -114,10 +121,10 @@ int main(void) { | 
| 114 | 121 |      * | 
| 115 | 122 |      * Here we are preventing these writes from being optimized out, as any good compiler | 
| 116 | 123 |      * will remove any writes that aren't used. */ | 
| 117 |  | -    memset(seckey1, 0, sizeof(seckey1)); | 
| 118 |  | -    memset(seckey2, 0, sizeof(seckey2)); | 
| 119 |  | -    memset(shared_secret1, 0, sizeof(shared_secret1)); | 
| 120 |  | -    memset(shared_secret2, 0, sizeof(shared_secret2)); | 
|  | 124 | +    secure_erase(seckey1,sizeof(seckey1)); | 
|  | 125 | +    secure_erase(seckey2,sizeof(seckey2)); | 
|  | 126 | +    secure_erase(shared_secret1,sizeof(shared_secret1)); | 
|  | 127 | +    secure_erase(shared_secret2,sizeof(shared_secret2)); | 
| 121 | 128 | 
 | 
| 122 | 129 |     return 0; | 
| 123 | 130 | } | 
0 commit comments