| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include "operations.h" |
| 10 |
|
| 11 |
#include "hash.h" |
| 12 |
#include "decrypt.h" |
| 13 |
#include "params.h" |
| 14 |
#include "util.h" |
| 15 |
|
| 16 |
#include <stdint.h> |
| 17 |
#include <string.h> |
| 18 |
#include "crypto_int8.h" |
| 19 |
#include "crypto_uint8.h" |
| 20 |
|
| 21 |
|
| 22 |
static int check_c_padding(const unsigned char * c) |
| 23 |
{ |
| 24 |
unsigned char b; |
| 25 |
|
| 26 |
b = c[ SYND_BYTES-1 ] >> (PK_NROWS % 8); |
| 27 |
return crypto_int8_nonzero_mask(b); |
| 28 |
} |
| 29 |
|
| 30 |
int operation_dec( |
| 31 |
unsigned char *key, |
| 32 |
const unsigned char *c, |
| 33 |
const unsigned char *sk |
| 34 |
) |
| 35 |
{ |
| 36 |
int i, padding_ok; |
| 37 |
|
| 38 |
unsigned char mask; |
| 39 |
unsigned char fail = 0; |
| 40 |
|
| 41 |
unsigned char m; |
| 42 |
|
| 43 |
unsigned char e[ SYS_N/8 ]; |
| 44 |
unsigned char preimage[ 1 + SYS_N/8 + SYND_BYTES ]; |
| 45 |
unsigned char *x = preimage; |
| 46 |
const unsigned char *s = sk + 40 + IRR_BYTES + COND_BYTES; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
padding_ok = check_c_padding(c); |
| 51 |
|
| 52 |
fail = decrypt(e, sk + 40, c); |
| 53 |
|
| 54 |
m = crypto_uint8_zero_mask(fail); |
| 55 |
|
| 56 |
*x++ = crypto_uint8_bottombit_01(m); |
| 57 |
for (i = 0; i < SYS_N/8; i++) |
| 58 |
*x++ = (~m & s[i]) | (m & e[i]); |
| 59 |
|
| 60 |
for (i = 0; i < SYND_BYTES; i++) |
| 61 |
*x++ = c[i]; |
| 62 |
|
| 63 |
crypto_hash_32b(key, preimage, sizeof(preimage)); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
mask = padding_ok; |
| 68 |
|
| 69 |
for (i = 0; i < 32; i++) |
| 70 |
key[i] |= mask; |
| 71 |
|
| 72 |
return padding_ok; |
| 73 |
} |
| 74 |
|