Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
ctidh_api.c File Reference
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <immintrin.h>
#include "../common/fips202.h"
#include "../common/fp/mulx/fp.h"
#include "../common/namespace.h"
#include "../common/primes.h"
#include "ctidh.h"
#include "ctidh_api.h"
Include dependency graph for ctidh_api.c:

Go to the source code of this file.

Macros

#define HASH_BYTES   NUMBER_OF_WORDS*8
 
#define HASH(data, len, out)   shake256(out, HASH_BYTES, data, len);
 
#define secsidh_keygen   NSAPI(keygen)
 
#define secsidh_derive   NSAPI(derive)
 
#define cprintf(...)   printf(__VA_ARGS__)
 
#define SECSIDH_SUCCESS   0
 
#define SECSIDH_FAILURE   -1
 

Functions

const size_t NSAPI (pk_size)
 
const size_t NSAPI (sk_size)
 
const size_t NSAPI (ss_size)
 
void internal_keygen (public_key *pk, private_key *sk)
 
bool internal_derive (fp *ss, public_key *const pk, private_key *const sk)
 
void skgen (int8_t *sk)
 
void pkgen (public_key *pk, int8_t *const sk)
 
int secsidh_keygen (uint8_t *pk, uint8_t *sk)
 
int secsidh_derive (uint8_t *ss, const uint8_t *peer_pk, const uint8_t *sk)
 

Macro Definition Documentation

◆ cprintf

#define cprintf (   ...)    printf(__VA_ARGS__)

Definition at line 32 of file ctidh_api.c.

◆ HASH

#define HASH (   data,
  len,
  out 
)    shake256(out, HASH_BYTES, data, len);

Definition at line 9 of file ctidh_api.c.

◆ HASH_BYTES

#define HASH_BYTES   NUMBER_OF_WORDS*8

Definition at line 8 of file ctidh_api.c.

◆ secsidh_derive

#define secsidh_derive   NSAPI(derive)

Definition at line 30 of file ctidh_api.c.

◆ SECSIDH_FAILURE

#define SECSIDH_FAILURE   -1

Definition at line 93 of file ctidh_api.c.

◆ secsidh_keygen

#define secsidh_keygen   NSAPI(keygen)

Definition at line 29 of file ctidh_api.c.

◆ SECSIDH_SUCCESS

#define SECSIDH_SUCCESS   0

Definition at line 92 of file ctidh_api.c.

Function Documentation

◆ internal_derive()

bool internal_derive ( fp ss,
public_key *const  pk,
private_key *const  sk 
)

Definition at line 63 of file ctidh_api.c.

64{
65
66#ifdef ENABLE_CT_TESTING
68#endif
69
70 if (!validate((public_key*)pk)) return 0; // validating the input Montgomery curve affine coefficiente (it must be supersingular!)
71
73 action((public_key*)&shared, pk, sk); // Secrect sharing Montgomery curve affine coefficient: [sk] * pk
74
75 //HASH((uint8_t*)shared.A, sizeof(fp), (uint8_t*) ss);
76 fp_copy(*ss, shared.A);
77 return 1;
78}
#define validate
Definition ctidh.h:53
#define action
Definition ctidh.h:54
#define fp_copy
Definition fp-gmp.h:79
for i

References action, fp_copy, i, and validate.

◆ internal_keygen()

void internal_keygen ( public_key pk,
private_key sk 
)

Definition at line 46 of file ctidh_api.c.

47{
48 ctidh_private((private_key*) sk); // random private integer vector
49
51
52 // we need to compute the seed of the full order point
53 fp u;
55
56 pk->seed = u[0];
57 printf("seed: %ld\n", pk->seed);
58}
#define ctidh_private
Definition ctidh.h:47
#define base
Definition ctidh.h:44
#define fulltorsion_points
Definition ctidh.h:57
uint64_t fp[NUMBER_OF_WORDS]
Definition fp-gmp.h:22

References action, base, ctidh_private, fulltorsion_points, and i.

◆ NSAPI() [1/3]

const size_t NSAPI ( pk_size  )

◆ NSAPI() [2/3]

const size_t NSAPI ( sk_size  )

◆ NSAPI() [3/3]

const size_t NSAPI ( ss_size  )

◆ pkgen()

void pkgen ( public_key pk,
int8_t *const  sk 
)

Definition at line 85 of file ctidh_api.c.

86{
88}

References action, base, and i.

◆ secsidh_derive()

int secsidh_derive ( uint8_t ss,
const uint8_t peer_pk,
const uint8_t sk 
)

Definition at line 202 of file ctidh_api.c.

203{
204 int ret;
205 public_key ipeer_pk = {0};
206 fp iss;
208
209 secsidh_oct2pk(&ipeer_pk, peer_pk);
210 memset(&iss, 0, sizeof(fp));
211
212 secsidh_oct2sk(&isk, sk);
213
215
216
217 secsidh_clear(&isk, sizeof(isk));
218 secsidh_ss2oct(ss, (const fp*)iss);
219 secsidh_clear(iss, sizeof(iss));
220
221 return ret;
222}
#define SECSIDH_FAILURE
Definition ctidh_api.c:93
#define SECSIDH_SUCCESS
Definition ctidh_api.c:92
#define internal_derive
Definition ctidh_api.h:23

References i, internal_derive, SECSIDH_FAILURE, and SECSIDH_SUCCESS.

◆ secsidh_keygen()

int secsidh_keygen ( uint8_t pk,
uint8_t sk 
)

Definition at line 187 of file ctidh_api.c.

188{
189 public_key ipk[2] = {0};
192
193
194 secsidh_pk2oct(pk, (const public_key*)ipk);
195
196 secsidh_sk2oct(sk, &isk);
197 secsidh_clear(&isk, sizeof(isk));
198
199 return SECSIDH_SUCCESS;
200}
#define internal_keygen
Definition ctidh_api.h:21

References i, internal_keygen, and SECSIDH_SUCCESS.

◆ skgen()

void skgen ( int8_t sk)

Definition at line 80 of file ctidh_api.c.

81{
83}

References ctidh_private, and i.