Skip to content

Commit

Permalink
xwing: review + sct.
Browse files Browse the repository at this point in the history
  • Loading branch information
tfaoliveira-sb committed Apr 16, 2024
1 parent 7540ffa commit 600212c
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 461 deletions.
7 changes: 7 additions & 0 deletions src/crypto_kem/mlkem/mlkem768/amd64/ref/params.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ param int MLKEM_CT_LEN = MLKEM_POLYVECCOMPRESSEDBYTES + MLKEM_POLYCOMPRESSEDBYTE
param int MLKEM_INDCPA_PUBLICKEYBYTES = MLKEM_POLYVECBYTES + MLKEM_SYMBYTES;
param int MLKEM_PUBLICKEYBYTES = MLKEM_INDCPA_PUBLICKEYBYTES;
param int MLKEM_SSBYTES = 32;

// the following is a patch to handle inconsistencies between ref/params.jinc and avx2/params.jinc (motivated by xwing);
// this needs to be fixed upstream, in formosa-mlkem
param int MLKEM_INDCPA_CIPHERTEXTBYTES = MLKEM_POLYVECCOMPRESSEDBYTES + MLKEM_POLYCOMPRESSEDBYTES;
param int MLKEM_INDCPA_SECRETKEYBYTES = MLKEM_POLYVECBYTES;
param int MLKEM_SECRETKEYBYTES = MLKEM_INDCPA_SECRETKEYBYTES + MLKEM_INDCPA_PUBLICKEYBYTES + 2*MLKEM_SYMBYTES;
param int MLKEM_CIPHERTEXTBYTES = MLKEM_INDCPA_CIPHERTEXTBYTES;
6 changes: 3 additions & 3 deletions src/crypto_kem/xwing/META.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: X-Wing
type: kem
checksumsmall: 844bca7a113f642135f10d7ab047f8fbc137a6d0c7bbe64dbde0b48c46681872
checksumbig: 05451934bd516a3b885896e7e448d9739ed1ccc67339f438db230bd479f026bb
checksumsmall: d80f0bfdf6d38a189cfffe48c048973521c02456bde1934475c38e0819c4afae
checksumbig: 607234d1da70d4441c64c8bb3deff3f22728a38942500457c92dbcdaf393d0c0
claimed-nist-level: 3
claimed-security: IND-CCA2
length-public-key: 1216
Expand All @@ -23,4 +23,4 @@ implementations:
required_flags: # FIXME
- avx2
- bmi2
- popcnt
- popcnt
54 changes: 38 additions & 16 deletions src/crypto_kem/xwing/amd64/avx2/kem.jazz
Original file line number Diff line number Diff line change
@@ -1,69 +1,91 @@
require "params.jinc"
require "kem.jinc"
from Jade require "common/tofromstack.jinc"

from Jade require "crypto_kem/mlkem/mlkem768/amd64/avx2/kem.jinc"
from Jade require "crypto_kem/xwing/amd64/ref/kem.jinc"
from Jade require "crypto_kem/xwing/amd64/ref/params.jinc"

export fn jade_kem_xwing_amd64_avx2_keypair_derand(reg u64 public_key secret_key coins) -> reg u64
{
reg u64 r;
stack u8[96] stack_coins;
reg u64 r;
stack u8[XWING_KEYPAIRCOINBYTES] stack_coins;

public_key = public_key;
secret_key = secret_key;
_ = #init_msf();

stack_coins = __tostack96u8(stack_coins, coins);
public_key = public_key;
secret_key = secret_key;
stack_coins = __tostack96u8(stack_coins, coins);

_crypto_xkem_keypair_derand_jazz(public_key, secret_key, stack_coins);
_crypto_xkem_keypair_derand_jazz(public_key, secret_key, stack_coins);

?{}, r = #set0();
return r;
?{}, r = #set0();
return r;
}


export fn jade_kem_xwing_amd64_avx2_keypair(reg u64 public_key secret_key) -> reg u64
{
reg u64 r;
stack u8[96] stack_coins;
stack u8[XWING_KEYPAIRCOINBYTES] stack_coins;

_ = #init_msf();

public_key = public_key;
secret_key = secret_key;
stack_coins = #randombytes(stack_coins);

_crypto_xkem_keypair_derand_jazz(public_key, secret_key, stack_coins);

?{}, r = #set0();
return r;
}

export fn jade_kem_xwing_amd64_avx2_enc_derand(reg u64 ciphertext shared_secret public_key coins) -> reg u64
{
reg u64 r;
stack u8[64] stack_coins;

stack u8[XWING_ENCCOINBYTES] stack_coins;

_ = #init_msf();

ciphertext = ciphertext;
shared_secret = shared_secret;
public_key = public_key;
stack_coins = __tostack64u8(stack_coins, coins);

_crypto_xkem_enc_derand_jazz(ciphertext, shared_secret, public_key, stack_coins);

?{}, r = #set0();
return r;
}

export fn jade_kem_xwing_amd64_avx2_enc(reg u64 ciphertext shared_secret public_key) -> reg u64
{
reg u64 r;
stack u8[64] stack_coins;
stack u8[XWING_ENCCOINBYTES] stack_coins;

_ = #init_msf();

ciphertext = ciphertext;
shared_secret = shared_secret;
public_key = public_key;
stack_coins = #randombytes(stack_coins);

_crypto_xkem_enc_derand_jazz(ciphertext, shared_secret, public_key, stack_coins);

?{}, r = #set0();
return r;
}

export fn jade_kem_xwing_amd64_avx2_dec(reg u64 shared_secret ciphertext secret_key) -> reg u64
{
reg u64 r;
__crypto_xkem_dec_jazz(shared_secret, ciphertext, secret_key);

_ = #init_msf();

shared_secret = shared_secret;
ciphertext = ciphertext;
secret_key = secret_key;

_crypto_xkem_dec_jazz(shared_secret, ciphertext, secret_key);

?{}, r = #set0();
return r;
}
Expand Down
171 changes: 0 additions & 171 deletions src/crypto_kem/xwing/amd64/avx2/kem.jinc

This file was deleted.

21 changes: 0 additions & 21 deletions src/crypto_kem/xwing/amd64/avx2/params.jinc

This file was deleted.

33 changes: 0 additions & 33 deletions src/crypto_kem/xwing/amd64/avx2/scalarmult_mulx.jinc

This file was deleted.

Loading

0 comments on commit 600212c

Please sign in to comment.