Skip to content

Commit 25f7f83

Browse files
authored
Merge pull request #347 from anhu/pqm4_update
Update PQM4 kyber setup script.
2 parents fe060a7 + 43882bd commit 25f7f83

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-35
lines changed

pq/stm32/README.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,36 @@ $ make
2929

3030
## Configuring the STM32CubeIDE Project
3131

32-
Please see the following video for highlights on how the project was configured
33-
and how to configure wolfSSL to enable our PQM4 integration.
32+
Please see the following video for highlights on how to configure wolfSSL to
33+
enable our PQM4 integration.
3434

3535
https://www.youtube.com/watch?v=OK6MKXYiVBY
3636

37-
To setup the required PQM4 source files, please run the `setup_kyber.sh` script
38-
in this directory. It will clone releveant git repos from github and generate
39-
the directories and files you need.
37+
Detailed instructions on how to build a project with wolfssl can be found at:
38+
39+
https://github.com/wolfSSL/wolfssl/tree/master/IDE/STM32Cube
40+
41+
1. Follow instructions at the link above and make sure you can perform "Example
42+
for TLS v1.3 over UART".
43+
2. Run the `setup_kyber.sh` script in this directory. It will clone relevant
44+
git repos from github and generate the directories and files you need.
45+
3. Drag and drop the include files into `Inc` and the `pqm4_kyber512` directory
46+
into `Core`.
47+
4. Turn on the PQM4 integration.
48+
- Open the .ioc file
49+
- Click "Software Packs"
50+
- Click on the wolfSSL.I-CUBE-wolfSSL.<version> that appears.
51+
- In the Configuration box that appears, set "PQM4 Post-Quantum Integration
52+
Support" to "True"
53+
- Close the .ioc file and generate code.
54+
- Build your project.
55+
56+
For your reference, `wolfssl_stm32_pq` is a minimal starting project that has
57+
many things already configured. If you have a NUCLEO-F446ZE evaluation board
58+
Then you can skip step 1 and 4 and just use that.
4059

4160
Once you have successfully built and flashed the project, the STM32 terminal
42-
should should display the following menu:
61+
should should display the following menu:
4362

4463
```
4564
MENU
@@ -92,7 +111,7 @@ ECDSA [ SECP256R1] 256 sign 78 ops took 1.019 sec, avg 13.064 m
92111
ECDSA [ SECP256R1] 256 verify 38 ops took 1.012 sec, avg 26.632 ms, 37.549 ops/sec
93112
kyber_level1-kg 62 ops took 1.004 sec, avg 16.194 ms, 61.753 ops/sec
94113
kyber_level1-ed 28 ops took 1.043 sec, avg 37.250 ms, 26.846 ops/sec
95-
Benchmark complete
114+
Benchmark complete
96115
```
97116

98117
## Quantum safe TLS 1.3 Connection Over UART (Linux server, STM32 client)

pq/stm32/setup_kyber.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ diff -u pqm4_kyber512.old/kem.c pqm4_kyber512/kem.c
1010
diff -u pqm4_kyber512.old/randombytes.c pqm4_kyber512/randombytes.c
1111
--- pqm4_kyber512.old/randombytes.c 2022-03-28 16:36:40.037940919 -0400
1212
+++ pqm4_kyber512/randombytes.c 2022-03-11 14:38:18.192717915 -0500
13-
@@ -320,6 +320,10 @@
14-
/* Use windows API */
15-
return randombytes_win32_randombytes(buf, n);
13+
@@ -357,6 +357,10 @@
14+
/* Use WASI */
15+
return randombytes_wasi_randombytes(buf, n);
1616
#else
17-
-#error "randombytes(...) is not supported on this platform"
17+
-# error "randombytes(...) is not supported on this platform"
1818
+ #warning randombytes() is not supported on this platform!
1919
+ for (size_t i = 0; i < n; i++) {
20-
+ buf[i] = (uint8_t)i;
21-
+ }
20+
+ output[i] = (uint8_t)i;
21+
+ }
2222
+ return 0;
2323
#endif
2424
}

pq/stm32/setup_kyber.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ tmp_dir=$PWD
1414

1515
git clone https://github.com/mupq/pqm4.git $tmp_dir/pqm4
1616
cd $tmp_dir/pqm4
17-
git checkout 3bfbbfd30401bd1dce3c497feb2a152713f2e735
17+
git checkout 1eeb74e4106a80e26a9452e4793acd6f191fe413
1818

1919
git clone https://github.com/mupq/mupq.git $tmp_dir/mupq
2020
cd $tmp_dir/mupq
21-
git checkout 0235e325b60dcbd41bc82cdee55b5e3940e70b3e
21+
git checkout 3b48fa5aff6f5921df5b3444450281daca6d21d1
2222

2323
git clone https://github.com/pqclean/pqclean.git $tmp_dir/pqclean
2424
cd $tmp_dir/pqclean
25-
git checkout 964469d5506f3068c5afb504e3406f3291f6c336
25+
git checkout 2cc6e744e63c9aa7703ba3ae3304215e83bba167
2626

2727
# Populate include directory
2828
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/params.h $inc_dir
@@ -52,12 +52,12 @@ cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/macros.i $code_dir
5252
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/matacc.c $code_dir
5353
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/matacc.h $code_dir
5454
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/matacc.i $code_dir
55-
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/matacc.S $code_dir
55+
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/matacc_asm.S $code_dir
5656
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/ntt.c $code_dir
5757
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/ntt.h $code_dir
5858
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/poly.c $code_dir
5959
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/poly.h $code_dir
60-
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/poly.S $code_dir
60+
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/poly_asm.S $code_dir
6161
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/polyvec.c $code_dir
6262
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/polyvec.h $code_dir
6363
cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/reduce.S $code_dir
@@ -68,16 +68,14 @@ cp $tmp_dir/pqm4/crypto_kem/kyber512/m4fspeed/verify.h $code_dir
6868

6969
# Rename some files
7070
mv $inc_dir/api.h $inc_dir/api_kyber.h
71-
mv $code_dir/matacc.S $code_dir/matacc_renamed.S
72-
mv $code_dir/poly.S $code_dir/poly_renamed.S
7371

7472
# Patch in some small fixups.
7573
cd $cur_dir
7674
patch -p0 < setup_kyber.patch
7775

7876
# give the user some instructions
79-
echo "Created $code_dir . Plese add it to your project's Core directory."
80-
echo "Created $inc_dir . Plese add the files it contains to you project's Core/Inc directory."
77+
echo "Created $code_dir . Please add it to your project's Core directory."
78+
echo "Created $inc_dir . Please add the files it contains to you project's Core/Inc directory."
8179

8280
# Cleanup
8381
rm -rf $tmp_dir

pq/stm32/wolfssl_stm32_pq/wolfssl_stm32_pq.ioc

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Dma.USART2_RX.0.Priority=DMA_PRIORITY_LOW
1313
Dma.USART2_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode
1414
File.Version=6
1515
KeepUserPlacement=false
16+
Mcu.CPN=STM32F446ZET6
1617
Mcu.Family=STM32F4
1718
Mcu.IP0=DMA
1819
Mcu.IP1=NVIC
@@ -41,32 +42,34 @@ Mcu.Pin2=PC15-OSC32_OUT
4142
Mcu.Pin20=PB7
4243
Mcu.Pin21=VP_RTC_VS_RTC_Activate
4344
Mcu.Pin22=VP_SYS_VS_Systick
45+
Mcu.Pin23=VP_wolfSSL.I-CUBE-wolfSSL_VS_wolfSSLJjwolfSSL_5.5.3_5.5.3
4446
Mcu.Pin3=PH0-OSC_IN
4547
Mcu.Pin4=PH1-OSC_OUT
4648
Mcu.Pin5=PB0
4749
Mcu.Pin6=PB14
4850
Mcu.Pin7=PD8
4951
Mcu.Pin8=PD9
5052
Mcu.Pin9=PG6
51-
Mcu.PinsNb=23
52-
Mcu.ThirdPartyNb=0
53+
Mcu.PinsNb=24
54+
Mcu.ThirdParty0=wolfSSL.I-CUBE-wolfSSL.5.5.3
55+
Mcu.ThirdPartyNb=1
5356
Mcu.UserConstants=
5457
Mcu.UserName=STM32F446ZETx
5558
MxCube.Version=6.3.0
5659
MxDb.Version=DB.6.0.30
57-
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false
58-
NVIC.DMA1_Stream5_IRQn=true\:0\:0\:false\:false\:true\:false\:true
59-
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false
60+
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
61+
NVIC.DMA1_Stream5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
62+
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
6063
NVIC.ForceEnableDMAVector=true
61-
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false
62-
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true\:false
63-
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true\:false
64-
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:true\:false
64+
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
65+
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
66+
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
67+
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
6568
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
66-
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:true\:false
67-
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:true\:true
68-
NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true
69-
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false
69+
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
70+
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:false
71+
NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
72+
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
7073
PA10.GPIOParameters=GPIO_Label
7174
PA10.GPIO_Label=USB_ID
7275
PA10.Locked=true
@@ -281,6 +284,17 @@ VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
281284
VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate
282285
VP_SYS_VS_Systick.Mode=SysTick
283286
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
287+
VP_wolfSSL.I-CUBE-wolfSSL_VS_wolfSSLJjwolfSSL_5.5.3_5.5.3.Mode=wolfSSLJjwolfSSL
288+
VP_wolfSSL.I-CUBE-wolfSSL_VS_wolfSSLJjwolfSSL_5.5.3_5.5.3.Signal=wolfSSL.I-CUBE-wolfSSL_VS_wolfSSLJjwolfSSL_5.5.3_5.5.3
284289
board=NUCLEO-F446ZE
285290
boardIOC=true
291+
wolfSSL.I-CUBE-wolfSSL.5.5.3.IPParameters=WOLF_CONF_PQM4,WOLF_CONF_DEBUG,WOLF_CONF_RNG,wolfSSLCcwolfSSLJjwolfSSLJjCore,wolfSSLCcwolfSSLJjwolfCryptJjCore,wolfSSLCcwolfSSLJjwolfCryptJjTest
292+
wolfSSL.I-CUBE-wolfSSL.5.5.3.WOLF_CONF_DEBUG=1
293+
wolfSSL.I-CUBE-wolfSSL.5.5.3.WOLF_CONF_PQM4=1
294+
wolfSSL.I-CUBE-wolfSSL.5.5.3.WOLF_CONF_RNG=1
295+
wolfSSL.I-CUBE-wolfSSL.5.5.3.wolfSSLCcwolfSSLJjwolfCryptJjCore=true
296+
wolfSSL.I-CUBE-wolfSSL.5.5.3.wolfSSLCcwolfSSLJjwolfCryptJjTest=true
297+
wolfSSL.I-CUBE-wolfSSL.5.5.3.wolfSSLCcwolfSSLJjwolfSSLJjCore=true
298+
wolfSSL.I-CUBE-wolfSSL.5.5.3.wolfSSLJjwolfSSL_Checked=true
299+
wolfSSL.I-CUBE-wolfSSL.5.5.3_SwParameter=wolfSSLCcwolfSSLJjwolfCryptJjCore\:true;wolfSSLCcwolfSSLJjwolfCryptJjTest\:true;wolfSSLCcwolfSSLJjwolfSSLJjCore\:true;
286300
isbadioc=false

0 commit comments

Comments
 (0)