Debian Codegraph @

crypto_kem/8192128pcf/vec/kem_dec.c

raw
1 // 20260619 djb: more cryptoint usage
2 // 20240805 djb: more cryptoint usage
3 // 20221230 djb: add linker lines
4 // 20221230 djb: split out of operations.c
5
6 // linker define operation_dec
7 // linker use decrypt
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_uint8.h"
19
20 int operation_dec(
21 unsigned char *key,
22 const unsigned char *c,
23 const unsigned char *sk
24 )
25 {
26 int i;
27
28 unsigned char fail = 0;
29
30 unsigned char m;
31
32 unsigned char conf[32];
33 unsigned char two_e[ 1 + SYS_N/8 ] = {2};
34 unsigned char *e = two_e + 1;
35 unsigned char preimage[ 1 + SYS_N/8 + (SYND_BYTES + 32) ];
36 unsigned char *x = preimage;
37 const unsigned char *s = sk + 40 + IRR_BYTES + COND_BYTES;
38
39 //
40
41 fail = decrypt(e, sk + 40, c);
42
43 crypto_hash_32b(conf, two_e, sizeof(two_e));
44
45 for (i = 0; i < 32; i++)
46 fail |= conf[i] ^ c[SYND_BYTES + i];
47
48 m = crypto_uint8_zero_mask(fail);
49
50 *x++ = crypto_uint8_bottombit_01(m);
51 for (i = 0; i < SYS_N/8; i++)
52 *x++ = (~m & s[i]) | (m & e[i]);
53
54 for (i = 0; i < SYND_BYTES + 32; i++)
55 *x++ = c[i];
56
57 crypto_hash_32b(key, preimage, sizeof(preimage));
58
59 return 0;
60 }
61