Debian Codegraph @

crypto_kem/6688128f/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 e[ SYS_N/8 ];
33 unsigned char preimage[ 1 + SYS_N/8 + SYND_BYTES ];
34 unsigned char *x = preimage;
35 const unsigned char *s = sk + 40 + IRR_BYTES + COND_BYTES;
36
37 //
38
39 fail = decrypt(e, sk + 40, c);
40
41 m = crypto_uint8_zero_mask(fail);
42
43 *x++ = crypto_uint8_bottombit_01(m);
44 for (i = 0; i < SYS_N/8; i++)
45 *x++ = (~m & s[i]) | (m & e[i]);
46
47 for (i = 0; i < SYND_BYTES; i++)
48 *x++ = c[i];
49
50 crypto_hash_32b(key, preimage, sizeof(preimage));
51
52 return 0;
53 }
54