Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 17 additions & 73 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,75 +1,19 @@
# project specific
ACVP-Server-1.1.0.39/
SLH-DSA-.*-1.rsp
.DS_STORE
.vscode/launch.json

xtest
__pycache__

_build
_prof
*.vvp
*.log
*.drc
*.bgn
*.bit
*.mmi
*.jou
xvlog.*
build
firmware.*
config.h
obj_dir/*
prof
pqse
syn_out

# Prerequisites
*.d

# Object files
# executables
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
./slh_sha2
./slh_dsa
./ACVP_test_functions
./ACVP_sig_test
./kat_test
./sha3_f1600
./ACVP_keygen_test
./sha2_256
./sha2_512
./slh_shake
./ACVP_ver_test
./sha3_api
48 changes: 48 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387


"version": "0.2.0",
"configurations": [
{
"name": "Debug kat_test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/slh/kat_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb" // or "gdb" for Linux/WSL
},
{
"name": "Debug ACVP_keygen_test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/slh/ACVP_keygen_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
},
{
"name": "Debug ACVP_sig_test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/slh/ACVP_sig_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}


12 changes: 12 additions & 0 deletions slh/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
./slh_sha2
./slh_dsa
./ACVP_test_functions
./ACVP_sig_test
./kat_test
./sha3_f1600
./ACVP_keygen_test
./sha2_256
./sha2_512
./slh_shake
./ACVP_ver_test
./sha3_api
Binary file added slh/ACVP_keygen_test
Binary file not shown.
120 changes: 120 additions & 0 deletions slh/ACVP_keygen_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "ACVP_tests.h"

// hardcoded example usage *******************************************************************

/*
from JSON ->

"parameterSet": "SLH-DSA-SHA2-128s",
"skSeed": "AC379F047FAAB2004F3AE32350AC9A3D",
"skPrf": "829FFF0AA59E956A87F3971C4D58E710",
"pkSeed": "0566D240CC519834322EAFBCC73C79F5",
"sk": "AC379F047FAAB2004F3AE32350AC9A3D829FFF0AA59E956A87F3971C4D58E7100566D240CC519834322EAFBCC73C79F5A4B84F02E8BF0CBD54017B2D3C494B57",
"pk": "0566D240CC519834322EAFBCC73C79F5A4B84F02E8BF0CBD54017B2D3C494B57"
*/

/*
static int hardcoded_keygen_rbg(uint8_t *x, size_t xlen)
{
size_t n = slh_dsa_sha2_128s.n;

char skSeedString[] = "AC379F047FAAB2004F3AE32350AC9A3D";
char skPrfString[] = "829FFF0AA59E956A87F3971C4D58E710";
char pkSeedString[] = "0566D240CC519834322EAFBCC73C79F5";

hexStringToByteArray(skSeedString,x);
hexStringToByteArray(skPrfString,x+n);
hexStringToByteArray(pkSeedString,x+2*n);

return 0;
}

int main()
{
uint8_t pk[MAX_PK_BYTES] = {0};
uint8_t sk[MAX_SK_BYTES] = {0};
uint8_t pk_expected[MAX_PK_BYTES] = {0};
uint8_t sk_expected[MAX_SK_BYTES] = {0};

char skString[] = "AC379F047FAAB2004F3AE32350AC9A3D829FFF0AA59E956A87F3971C4D58E7100566D240CC519834322EAFBCC73C79F5A4B84F02E8BF0CBD54017B2D3C494B57";
char pkString[] = "0566D240CC519834322EAFBCC73C79F5A4B84F02E8BF0CBD54017B2D3C494B57";
hexStringToByteArray(skString, sk_expected);
hexStringToByteArray(pkString, pk_expected);

slh_keygen(pk,sk,&hardcoded_keygen_rbg,&slh_dsa_sha2_128s);

if(memcmp(sk,sk_expected,sizeof(sk)))
{
printf("SK does not match expected value! \r\n");
return -1;
}

else if(memcmp(pk,pk_expected,sizeof(pk)))
{
printf("PK does not match expected value! \r\n");
return -1;
}

printf("All tests passed! \r\n");
return 0;
}
*/

/*
arg 1 := tgId
arg 2 := tcId
arg 3 := prmSet
arg 4 := skSeed
arg 5 := skPrf
arg 6 := pkSeed
arg 7 := sk
arg 8 := pk
*/

int main(int argc, char *argv[])
{
/* one of the args is arg 0 */
if(argc != 9)
{
printf("%d \r\n", argc);
printf("Usage: ./ACVP_keygen_test <tgId> <tcId> <prmSet> <skSeed> <skPrf> <pkSeed> <sk> <pk> \r\n");
return -1;
}

uint8_t sk[MAX_SK_BYTES] = {0};
uint8_t pk[MAX_PK_BYTES] = {0};
uint8_t skExpected[MAX_SK_BYTES] = {0};
uint8_t pkExpected[MAX_PK_BYTES] = {0};

/* process arg vars */
uint8_t tgId = (uint8_t)atoi(argv[1]);
uint8_t tcId = (uint8_t)atoi(argv[2]);
selectPrmSet(argv[3],&prmSet_g);
seed_g.skSeedString = argv[4];
seed_g.skPrfString = argv[5];
seed_g.pkSeedString = argv[6];
hexStringToByteArray(argv[7], skExpected);
hexStringToByteArray(argv[8], pkExpected);

slh_keygen(pk,sk,fixedKeygenRbg,prmSet_g);

if(memcmp(sk,skExpected,sizeof(sk)))
{
printf("SK does not match expected value in keygen for (tgId,tcId): (%d,%d)! \r\n", tgId, tcId);
return -1;
}

else if(memcmp(pk,pkExpected,sizeof(pk)))
{
printf("PK does not match expected value in keygen for (tgId,tcId): (%d,%d)! \r\n", tgId, tcId);
return -1;
}

printf("Correct output for (tgId,tcId): (%d,%d)! \r\n", tgId, tcId);

return 0;
}
Binary file added slh/ACVP_sig_test
Binary file not shown.
90 changes: 90 additions & 0 deletions slh/ACVP_sig_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "ACVP_tests.h"
#include "slh_dsa.h"

/*
arg 1 := tgId
arg 2 := tcId
arg 3 := prmSet
arg 4 := deterministic
arg 5 := interface
arg 6 := m_sz
arg 7 := m
arg 8 := ctxlen
arg 9 := ctxStr
arg 10 := sk
arg 11 := sig
arg 12 := addRnd
*/


int main(int argc, char *argv[])
{
/* one of the args is arg 0 */
if(argc != 13)
{
printf("Arg count is %d! \r\n", argc);
printf("Usage: ./ACVP_sig_test <tgId> <tcId> <prmSet> <deterministic> <interface> <m_sz> <m> <ctxLen> <ctxStr> <sk> <sig> <addRnd> \r\n");
return -1;
}

/* process arg vars */
uint8_t tgId = (uint8_t)atoi(argv[1]);
uint8_t tcId = (uint8_t)atoi(argv[2]);
selectPrmSet(argv[3],&prmSet_g);
deterministic_g = (!strcmp(argv[4],"True")) ? SLH_DETERMINISTIC : SLH_NON_DETERMINISTIC;
interface_e interface = (!strcmp(argv[5],"internal")) ? SLH_INTERNAL : SLH_EXTERNAL;
size_t m_sz = atoi(argv[6])/2;
uint8_t *m = (uint8_t *)malloc(m_sz * sizeof(uint8_t));
if(m_sz != 0)
{
hexStringToByteArray(argv[7], m);
}
size_t ctxLen = atoi(argv[8])/2;
uint8_t *ctxStr = (uint8_t *)malloc(ctxLen * sizeof(uint8_t));

if(interface == SLH_EXTERNAL && ctxLen != 0)
{
hexStringToByteArray(argv[9], ctxStr);
}
uint8_t sk[MAX_SK_BYTES] = {0};
hexStringToByteArray(argv[10], sk);
size_t sig_sz = strlen(argv[11]);
uint8_t *sig = (uint8_t *)malloc(sig_sz * sizeof(uint8_t));
memset(sig,0,sig_sz);
uint8_t *sigExpected = (uint8_t *)malloc(sig_sz * sizeof(uint8_t));
hexStringToByteArray(argv[11], sigExpected);
if(deterministic_g == SLH_NON_DETERMINISTIC){hexStringToByteArray(argv[12], addRnd_g);}

if(interface == SLH_EXTERNAL)
{
slh_sign(sig,m,m_sz, ctxStr,ctxLen, sk,fixedSigRbg,prmSet_g);
}
else {
slh_sign_internal(sig,m,m_sz,sk,0,0,prmSet_g,addRnd_g);
}

if(memcmp(sig,sigExpected,sig_sz))
{
printf("Signature does not match expected value for (tgId,tcId): (%d,%d)! \r\n", tgId, tcId);

free(m);
free(ctxStr);
free(sig);
free(sigExpected);

return -1;
}
printf("Signature matches expected value for (tgId,tcId): (%d,%d)! \r\n", tgId, tcId);

free(m);
free(ctxStr);
free(sig);
free(sigExpected);

return 0;
}
Loading