├── android └── Key20 │ ├── .idea │ ├── .name │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── vcs.xml │ ├── modules.xml │ ├── runConfigurations.xml │ ├── compiler.xml │ ├── gradle.xml │ └── misc.xml │ ├── app │ ├── .gitignore │ ├── libs │ │ ├── core-1.54.0.0.jar │ │ ├── ecdh-curve25519.jar │ │ └── prov-1.54.0.0.jar │ ├── src │ │ ├── main │ │ │ ├── jniLibs │ │ │ │ ├── x86 │ │ │ │ │ └── libecdhcurve25519.so │ │ │ │ ├── mips │ │ │ │ │ └── libecdhcurve25519.so │ │ │ │ ├── mips64 │ │ │ │ │ └── libecdhcurve25519.so │ │ │ │ ├── x86_64 │ │ │ │ │ └── libecdhcurve25519.so │ │ │ │ ├── armeabi │ │ │ │ │ └── libecdhcurve25519.so │ │ │ │ ├── arm64-v8a │ │ │ │ │ └── libecdhcurve25519.so │ │ │ │ └── armeabi-v7a │ │ │ │ │ └── libecdhcurve25519.so │ │ │ ├── res │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── drawable-hdpi │ │ │ │ │ ├── ic_action_refresh.png │ │ │ │ │ ├── ic_lock_open_white_24dp.png │ │ │ │ │ ├── ic_vpn_key_white_24dp.png │ │ │ │ │ └── ic_bluetooth_searching_white_24dp.png │ │ │ │ ├── drawable-mdpi │ │ │ │ │ ├── ic_action_refresh.png │ │ │ │ │ ├── ic_lock_open_white_24dp.png │ │ │ │ │ ├── ic_vpn_key_white_24dp.png │ │ │ │ │ └── ic_bluetooth_searching_white_24dp.png │ │ │ │ ├── drawable-xhdpi │ │ │ │ │ ├── ic_action_refresh.png │ │ │ │ │ ├── ic_vpn_key_white_24dp.png │ │ │ │ │ ├── ic_lock_open_white_24dp.png │ │ │ │ │ └── ic_bluetooth_searching_white_24dp.png │ │ │ │ ├── drawable-xxhdpi │ │ │ │ │ ├── ic_action_refresh.png │ │ │ │ │ ├── ic_vpn_key_white_24dp.png │ │ │ │ │ ├── ic_lock_open_white_24dp.png │ │ │ │ │ └── ic_bluetooth_searching_white_24dp.png │ │ │ │ ├── values │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── styles.xml │ │ │ │ │ └── strings.xml │ │ │ │ ├── menu │ │ │ │ │ ├── menu_deviceselection.xml │ │ │ │ │ └── menu_main.xml │ │ │ │ ├── values-w820dp │ │ │ │ │ └── dimens.xml │ │ │ │ └── layout │ │ │ │ │ ├── dialog_about.xml │ │ │ │ │ ├── textview_deviceselection.xml │ │ │ │ │ ├── activity_main.xml │ │ │ │ │ ├── fragment_unlock.xml │ │ │ │ │ ├── activity_device_selection.xml │ │ │ │ │ └── fragment_keyexchange.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── de │ │ │ │ └── frank_durr │ │ │ │ └── key20 │ │ │ │ ├── UnlockFragment.java │ │ │ │ └── KeyExchangeFragment.java │ │ ├── test │ │ │ └── java │ │ │ │ └── de │ │ │ │ └── frank_durr │ │ │ │ └── key20 │ │ │ │ └── ExampleUnitTest.java │ │ └── androidTest │ │ │ └── java │ │ │ └── de │ │ │ └── frank_durr │ │ │ └── key20 │ │ │ └── ApplicationTest.java │ ├── proguard-rules.pro │ └── build.gradle │ ├── settings.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── curve25519-cortexm0 ├── test │ ├── checksum │ ├── fail.h │ ├── randombytes.h │ ├── speed_stm32f0.sh │ ├── stack_stm32f0.sh │ ├── test_stm32f0.sh │ ├── fail.c │ ├── print.h │ ├── stack.c │ ├── randombytes.c │ ├── speed.c │ ├── print.c │ └── test.c ├── scalarmult.bc ├── stm32f0xx │ ├── startup_stm32f0xx.s │ ├── startup_stm32f0xx.lst │ ├── sbrk.c │ ├── system_stm32f0xx.h │ ├── stm32f0_linker.ld │ └── stm32f0xx_conf.h ├── curve25519-cortexm0.h ├── Makefile ├── cortex_m0_reduce25519.s ├── cortex_m0_mpy121666.s └── cc0_1.0 ├── images ├── key20_app_unlock_tab.png ├── key20_app_key_exchange_tab.png ├── key20_keyexchange_checksum.jpg ├── key20_door_lock_controller_1.jpg ├── key20_door_lock_controller_2.jpg ├── key20_app_and_door_lock_controller.jpg └── key20_door_lock_controller_schematic.png ├── NOTICE ├── nrf51 ├── nrf51422_ac_s110.ld ├── nrf51822_aa_s110.ld ├── app_event_queue.h ├── app_event_queue.c ├── pstorage_platform.h ├── Makefile ├── gcc_startup_nrf51.s └── nrf_drv_config.h ├── avrnacl ├── shared │ ├── consts.c │ └── bigint.c ├── crypto_verify │ └── verify.c ├── include │ └── bigint.h ├── crypto_hash │ └── sha512.c ├── crypto_auth │ └── hmac.c ├── avrnacl.h └── crypto_hashblocks │ └── sha512.c ├── hd44780nrf51 ├── hd44780nrf51.h └── hd44780nrf51.c ├── LICENSE-HARDWARE ├── LICENSE-SOFTWARE └── pcb └── libs └── bluetooth40-nrf51822.lbr /android/Key20/.idea/.name: -------------------------------------------------------------------------------- 1 | Key20 -------------------------------------------------------------------------------- /android/Key20/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android/Key20/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/checksum: -------------------------------------------------------------------------------- 1 | c8a71edd37b496ed9f1c763b86f1614b24215280e6d4c48b6cdf477f9f92af6c 2 | -------------------------------------------------------------------------------- /images/key20_app_unlock_tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/images/key20_app_unlock_tab.png -------------------------------------------------------------------------------- /curve25519-cortexm0/scalarmult.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/curve25519-cortexm0/scalarmult.bc -------------------------------------------------------------------------------- /images/key20_app_key_exchange_tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/images/key20_app_key_exchange_tab.png -------------------------------------------------------------------------------- /images/key20_keyexchange_checksum.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/images/key20_keyexchange_checksum.jpg -------------------------------------------------------------------------------- /curve25519-cortexm0/test/fail.h: -------------------------------------------------------------------------------- 1 | #ifndef FAIL_H 2 | #define FAIL_H 3 | 4 | void fail(const char *error); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /images/key20_door_lock_controller_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/images/key20_door_lock_controller_1.jpg -------------------------------------------------------------------------------- /images/key20_door_lock_controller_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/images/key20_door_lock_controller_2.jpg -------------------------------------------------------------------------------- /android/Key20/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /android/Key20/app/libs/core-1.54.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/libs/core-1.54.0.0.jar -------------------------------------------------------------------------------- /android/Key20/app/libs/ecdh-curve25519.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/libs/ecdh-curve25519.jar -------------------------------------------------------------------------------- /android/Key20/app/libs/prov-1.54.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/libs/prov-1.54.0.0.jar -------------------------------------------------------------------------------- /android/Key20/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /images/key20_app_and_door_lock_controller.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/images/key20_app_and_door_lock_controller.jpg -------------------------------------------------------------------------------- /images/key20_door_lock_controller_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/images/key20_door_lock_controller_schematic.png -------------------------------------------------------------------------------- /curve25519-cortexm0/stm32f0xx/startup_stm32f0xx.s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/curve25519-cortexm0/stm32f0xx/startup_stm32f0xx.s -------------------------------------------------------------------------------- /android/Key20/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /curve25519-cortexm0/stm32f0xx/startup_stm32f0xx.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/curve25519-cortexm0/stm32f0xx/startup_stm32f0xx.lst -------------------------------------------------------------------------------- /android/Key20/app/src/main/jniLibs/x86/libecdhcurve25519.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/jniLibs/x86/libecdhcurve25519.so -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/jniLibs/mips/libecdhcurve25519.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/jniLibs/mips/libecdhcurve25519.so -------------------------------------------------------------------------------- /android/Key20/app/src/main/jniLibs/mips64/libecdhcurve25519.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/jniLibs/mips64/libecdhcurve25519.so -------------------------------------------------------------------------------- /android/Key20/app/src/main/jniLibs/x86_64/libecdhcurve25519.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/jniLibs/x86_64/libecdhcurve25519.so -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Key20 2 | Copyright 2016 Frank Duerr 3 | 4 | This software includes code developed as part of Key20 by Frank Duerr. We share this code under the Apache 2.0 License. 5 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/jniLibs/armeabi/libecdhcurve25519.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/jniLibs/armeabi/libecdhcurve25519.so -------------------------------------------------------------------------------- /curve25519-cortexm0/test/randombytes.h: -------------------------------------------------------------------------------- 1 | #ifndef RANDOMBYTES_H 2 | #define RANDOMBYTES_H 3 | 4 | void randombytes(unsigned char *x,unsigned long long xlen); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/jniLibs/arm64-v8a/libecdhcurve25519.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/jniLibs/arm64-v8a/libecdhcurve25519.so -------------------------------------------------------------------------------- /android/Key20/app/src/main/jniLibs/armeabi-v7a/libecdhcurve25519.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/jniLibs/armeabi-v7a/libecdhcurve25519.so -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-hdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-hdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-mdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-mdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xhdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xhdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-hdpi/ic_lock_open_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-hdpi/ic_lock_open_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-hdpi/ic_vpn_key_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-hdpi/ic_vpn_key_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-mdpi/ic_lock_open_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-mdpi/ic_lock_open_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-mdpi/ic_vpn_key_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-mdpi/ic_vpn_key_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xhdpi/ic_vpn_key_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xhdpi/ic_vpn_key_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xxhdpi/ic_vpn_key_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xxhdpi/ic_vpn_key_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xhdpi/ic_lock_open_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xhdpi/ic_lock_open_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xxhdpi/ic_lock_open_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xxhdpi/ic_lock_open_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-hdpi/ic_bluetooth_searching_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-hdpi/ic_bluetooth_searching_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-mdpi/ic_bluetooth_searching_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-mdpi/ic_bluetooth_searching_white_24dp.png -------------------------------------------------------------------------------- /curve25519-cortexm0/test/speed_stm32f0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | DEVICE=/dev/ttyUSB0 3 | DIR=`dirname $0` 4 | 5 | stty -F $DEVICE raw icanon eof \^d 9600 6 | st-flash write $DIR/speed.bin 0x8000000 7 | cat < $DEVICE 8 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/stack_stm32f0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | DEVICE=/dev/ttyUSB0 3 | DIR=`dirname $0` 4 | 5 | stty -F $DEVICE raw icanon eof \^d 9600 6 | st-flash write $DIR/stack.bin 0x8000000 7 | cat < $DEVICE 8 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xhdpi/ic_bluetooth_searching_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xhdpi/ic_bluetooth_searching_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/drawable-xxhdpi/ic_bluetooth_searching_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duerrfk/key20/HEAD/android/Key20/app/src/main/res/drawable-xxhdpi/ic_bluetooth_searching_white_24dp.png -------------------------------------------------------------------------------- /android/Key20/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/test_stm32f0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | DEVICE=/dev/ttyUSB0 3 | DIR=`dirname $0` 4 | 5 | stty -F $DEVICE raw icanon eof \^d 9600 6 | st-flash write $DIR/test.bin 0x8000000 7 | cat < $DEVICE | diff - $DIR/checksum 8 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/fail.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "fail.h" 3 | #include "print.h" 4 | 5 | void fail(const char *error) 6 | { 7 | print("ERROR: "); 8 | print(error); 9 | print("\n"); 10 | //exit(-1); 11 | } 12 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /android/Key20/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 07 11:46:48 CEST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/print.h: -------------------------------------------------------------------------------- 1 | #ifndef PRINT_H 2 | #define PRINT_H 3 | 4 | void write_byte(unsigned char c); 5 | 6 | void print(const char *s); 7 | 8 | void bigint_print(const unsigned char *x, unsigned char xlen); 9 | 10 | void print_stack(const char *primitive, const unsigned int bytes, unsigned int stack); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #a30100 7 | #dddddd 8 | 9 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/menu/menu_deviceselection.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /android/Key20/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /android/Key20/app/src/test/java/de/frank_durr/key20/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package de.frank_durr.key20; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /android/Key20/app/src/androidTest/java/de/frank_durr/key20/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package de.frank_durr.key20; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /nrf51/nrf51422_ac_s110.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x18000, LENGTH = 0x28000 9 | RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x6000 10 | } 11 | 12 | SECTIONS 13 | { 14 | .fs_data_out ALIGN(4): 15 | { 16 | PROVIDE( __start_fs_data = .); 17 | KEEP(*(fs_data)) 18 | PROVIDE( __stop_fs_data = .); 19 | } = 0 20 | } 21 | 22 | INCLUDE "nrf5x_common.ld" 23 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/layout/dialog_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/layout/textview_deviceselection.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | -------------------------------------------------------------------------------- /avrnacl/shared/consts.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: avrnacl_8bitc/shared/consts.c 3 | * Author: Michael Hutter, Peter Schwabe 4 | * Version: 5 | * Public Domain 6 | */ 7 | 8 | 9 | const unsigned char avrnacl_sha512_iv[64] = { 10 | 0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08, 11 | 0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b, 12 | 0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b, 13 | 0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1, 14 | 0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1, 15 | 0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f, 16 | 0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b, 17 | 0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79 18 | } ; 19 | -------------------------------------------------------------------------------- /android/Key20/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /android/Key20/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 8 | 9 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /curve25519-cortexm0/curve25519-cortexm0.h: -------------------------------------------------------------------------------- 1 | #ifndef CURVE2519_H 2 | #define CURVE2519_H 3 | 4 | #define crypto_scalarmult crypto_scalarmult_curve25519 5 | #define crypto_scalarmult_base crypto_scalarmult_curve25519_base 6 | #define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES 7 | #define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES 8 | #define crypto_scalarmult_curve25519_BYTES 32 9 | #define crypto_scalarmult_curve25519_SCALARBYTES 32 10 | extern int crypto_scalarmult_curve25519(unsigned char *,const unsigned char *,const unsigned char *); 11 | extern int crypto_scalarmult_curve25519_base(unsigned char *,const unsigned char *); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /nrf51/nrf51822_aa_s110.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | /* nRF51822, Revision 3, Variant AA has 256 kB Flash and 16 KB of RAM. 7 | With softdevice S110 version 8, 8 kB RAM (0x2000) are left. 8 | S110 needs no heap, and 1536 bytes stack shared with the application stack. 9 | */ 10 | MEMORY 11 | { 12 | FLASH (rx) : ORIGIN = 0x18000, LENGTH = 0x28000 13 | RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 14 | } 15 | 16 | SECTIONS 17 | { 18 | .fs_data_out ALIGN(4): 19 | { 20 | PROVIDE( __start_fs_data = .); 21 | KEEP(*(fs_data)) 22 | PROVIDE( __stop_fs_data = .); 23 | } = 0 24 | } 25 | 26 | INCLUDE "nrf5x_common.ld" 27 | -------------------------------------------------------------------------------- /android/Key20/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/duerrfk/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /android/Key20/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /android/Key20/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /curve25519-cortexm0/stm32f0xx/sbrk.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "stm32f0xx_usart.h" 6 | 7 | #undef errno 8 | extern int errno; 9 | 10 | #ifndef __caddr_t_defined 11 | typedef __caddr_t caddr_t; 12 | #endif 13 | 14 | caddr_t _sbrk(int incr) 15 | { 16 | 17 | extern char _ebss; // Defined by the linker 18 | static char *heap_end; 19 | char *prev_heap_end; 20 | 21 | if (heap_end == 0) { 22 | heap_end = &_ebss; 23 | } 24 | prev_heap_end = heap_end; 25 | 26 | char * stack = (char*) __get_MSP(); 27 | if (heap_end + incr > stack) 28 | { 29 | //_write (STDERR_FILENO, "Heap and stack collision\n", 25); 30 | errno = ENOMEM; 31 | return (caddr_t) -1; 32 | // abort (); 33 | } 34 | 35 | heap_end += incr; 36 | return (caddr_t) prev_heap_end; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /avrnacl/crypto_verify/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: avrnacl_8bitc/crypto_verify/verify.c 3 | * Author: Michael Hutter, Peter Schwabe 4 | * Version: Tue Aug 12 08:23:16 2014 +0200 5 | * Public Domain 6 | */ 7 | 8 | /* 9 | * Based on tweetnacl.c version 20140427. 10 | * by Daniel J. Bernstein, Wesley Janssen, Tanja Lange, and Peter Schwabe 11 | */ 12 | 13 | #include "avrnacl.h" 14 | 15 | static int vn(const unsigned char *x,const unsigned char *y,char n) 16 | { 17 | crypto_uint8 i; 18 | crypto_uint16 d = 0; 19 | for(i=0;i> 8)) - 1; 22 | } 23 | 24 | int crypto_verify_16( 25 | const unsigned char *x, 26 | const unsigned char *y 27 | ) 28 | { 29 | return vn(x,y,16); 30 | } 31 | 32 | int crypto_verify_32( 33 | const unsigned char *x, 34 | const unsigned char *y 35 | ) 36 | { 37 | return vn(x,y,32); 38 | } 39 | -------------------------------------------------------------------------------- /android/Key20/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /android/Key20/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.0" 6 | 7 | defaultConfig { 8 | applicationId "de.frank_durr.key20" 9 | minSdkVersion 18 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.0.0' 26 | compile 'com.android.support:design:23.0.0' 27 | compile files('libs/core-1.54.0.0.jar') 28 | compile files('libs/prov-1.54.0.0.jar') 29 | compile files('libs/ecdh-curve25519.jar') 30 | } 31 | -------------------------------------------------------------------------------- /avrnacl/include/bigint.h: -------------------------------------------------------------------------------- 1 | #ifndef BIGINT_H 2 | #define BIGINT_H 3 | 4 | /* Arithmetic on big integers represented as arrays of unsigned char in radix 2^256 */ 5 | 6 | #define bigint_add avrnacl_bigint_add 7 | #define bigint_sub avrnacl_bigint_sub 8 | #define bigint_mul avrnacl_bigint_mul 9 | #define bigint_mul32 avrnacl_bigint_mul32 10 | #define bigint_cmov avrnacl_bigint_cmov 11 | 12 | unsigned char bigint_add(unsigned char r[32], const unsigned char a[32], const unsigned char b[32], unsigned int len); 13 | 14 | unsigned char bigint_sub(unsigned char r[32], const unsigned char a[32], const unsigned char b[32], unsigned int len); 15 | 16 | void bigint_mul(unsigned char *r, const unsigned char *a, const unsigned char *b, unsigned int len); 17 | 18 | void bigint_mul32(unsigned char *r, const unsigned char *a, const unsigned char *b); 19 | 20 | void bigint_cmov(unsigned char *r, const unsigned char *x, unsigned char b, unsigned int len); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../api.h" 3 | #include "print.h" 4 | #include "fail.h" 5 | #include "randombytes.h" 6 | 7 | #define nlen crypto_scalarmult_SCALARBYTES 8 | #define qlen crypto_scalarmult_BYTES 9 | 10 | #define MAXSTACK 1000 11 | 12 | unsigned char i; 13 | unsigned char n[nlen]; 14 | unsigned char q[qlen]; 15 | 16 | unsigned int ctr; 17 | unsigned char canary; 18 | volatile unsigned char *p; 19 | extern unsigned char _end; 20 | 21 | static unsigned int stack_count(unsigned char canary,volatile unsigned char *a) 22 | { 23 | volatile unsigned char *p = (a-MAXSTACK); 24 | unsigned int c = 0; 25 | while(*p == canary && p < a) 26 | { 27 | p++; 28 | c++; 29 | } 30 | return c; 31 | } 32 | 33 | #define WRITE_CANARY(X) {p=X;while(p>= (X-MAXSTACK)) *(p--) = canary;} 34 | 35 | int main(void) 36 | { 37 | volatile unsigned char a; /* Mark the beginning of the stack */ 38 | 39 | //randombytes(&canary,1); 40 | canary = 42; 41 | 42 | WRITE_CANARY(&a); 43 | crypto_scalarmult(q,n,q); 44 | ctr = MAXSTACK - stack_count(canary,&a); 45 | print_stack("crypto_scalarmult",-1,ctr); 46 | 47 | write_byte(4); 48 | while(1); 49 | } 50 | -------------------------------------------------------------------------------- /avrnacl/crypto_hash/sha512.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: avrnacl_8bitc/crypto_hash/sha512.c 3 | * Author: Michael Hutter, Peter Schwabe 4 | * Version: Tue Aug 12 08:23:16 2014 +0200 5 | * Public Domain 6 | */ 7 | 8 | /* 9 | * Based on tweetnacl.c version 20140427. 10 | * by Daniel J. Bernstein, Wesley Janssen, Tanja Lange, and Peter Schwabe 11 | */ 12 | 13 | #include "avrnacl.h" 14 | 15 | extern const unsigned char avrnacl_sha512_iv[64]; 16 | 17 | int crypto_hash_sha512( 18 | unsigned char *out, 19 | const unsigned char *m,crypto_uint16 mlen 20 | ) 21 | { 22 | unsigned char h[64]; 23 | unsigned char padded[256]; 24 | crypto_uint16 i,b = mlen; 25 | 26 | for(i=0;i<64;i++) 27 | h[i] = avrnacl_sha512_iv[i]; 28 | 29 | crypto_hashblocks_sha512(h,m,mlen); 30 | m += mlen; 31 | mlen &= 127; 32 | m -= mlen; 33 | 34 | for(i=0;i<256;i++) 35 | padded[i] = 0; 36 | for(i=0;i3;i--) 43 | padded[mlen-i] = 0; 44 | padded[mlen-3] = b >> 13; 45 | padded[mlen-2] = b >> 5; 46 | padded[mlen-1] = b << 3; 47 | 48 | crypto_hashblocks_sha512(h,padded,mlen); 49 | 50 | for(i=0;i<64;i++) 51 | out[i] = h[i]; 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/randombytes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * From try-anything.c version 20120328 3 | * by D. J. Bernstein 4 | */ 5 | 6 | typedef unsigned long uint32; 7 | 8 | static uint32 seed[32] = { 3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5 } ; 9 | static uint32 in[12]; 10 | static uint32 out[8]; 11 | static int outleft = 0; 12 | 13 | #define ROTATE(x,b) (((x) << (b)) | ((x) >> (32 - (b)))) 14 | #define MUSH(i,b) x = t[i] += (((x ^ seed[i]) + sum) ^ ROTATE(x,b)); 15 | 16 | static void surf(void) 17 | { 18 | uint32 t[12]; uint32 x; uint32 sum = 0; 19 | int r; int i; int loop; 20 | 21 | for (i = 0;i < 12;++i) t[i] = in[i] ^ seed[12 + i]; 22 | for (i = 0;i < 8;++i) out[i] = seed[24 + i]; 23 | x = t[11]; 24 | for (loop = 0;loop < 2;++loop) { 25 | for (r = 0;r < 16;++r) { 26 | sum += 0x9e3779b9; 27 | MUSH(0,5) MUSH(1,7) MUSH(2,9) MUSH(3,13) 28 | MUSH(4,5) MUSH(5,7) MUSH(6,9) MUSH(7,13) 29 | MUSH(8,5) MUSH(9,7) MUSH(10,9) MUSH(11,13) 30 | } 31 | for (i = 0;i < 8;++i) out[i] ^= t[i + 4]; 32 | } 33 | } 34 | 35 | void randombytes(unsigned char *x,unsigned long long xlen) 36 | { 37 | while (xlen > 0) { 38 | if (!outleft) { 39 | if (!++in[0]) if (!++in[1]) if (!++in[2]) ++in[3]; 40 | surf(); 41 | outleft = 8; 42 | } 43 | *x = out[--outleft]; 44 | ++x; 45 | --xlen; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 10 | 11 | 17 | 18 | 23 | 24 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /nrf51/app_event_queue.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Key20. 3 | * 4 | * Copyright 2016 Frank Duerr 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef APP_EVENT_QUEUE_H 20 | #define APP_EVENT_QUEUE_H 21 | 22 | #include 23 | 24 | #ifndef APP_EVENT_QUEUE_SIZE 25 | #define APP_EVENT_QUEUE_SIZE 16 26 | #endif 27 | 28 | struct app_event { 29 | uint8_t event_type; 30 | }; 31 | 32 | struct app_event_queue { 33 | struct app_event events[APP_EVENT_QUEUE_SIZE]; 34 | unsigned int size; 35 | unsigned int free; 36 | unsigned int head; 37 | unsigned int tail; 38 | }; 39 | 40 | void app_event_queue_init(struct app_event_queue *queue); 41 | 42 | int app_event_queue_add(struct app_event_queue *queue, struct app_event event); 43 | 44 | int app_event_queue_get(struct app_event_queue *queue, struct app_event *event); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/speed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "print.h" 4 | #include "../api.h" 5 | 6 | int main(void) 7 | { 8 | char out[500]; 9 | 10 | unsigned char secretKeyAlice[32];/* = 11 | { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 12 | 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 13 | 0x87, 0xeb, 0xc0, 0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 14 | 0x1d, 0xb9, 0x2c, 0x2a };*/ 15 | 16 | unsigned char expectedPublicKeyBob[32]; /*= 17 | { 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, 0xd3, 0x5b, 18 | 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 19 | 0xc8, 0x5b, 0x78, 0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 20 | 0x6f, 0x88, 0x2b, 0x4f };*/ 21 | 22 | unsigned char sharedSecretCalculatedByAlice[32]; 23 | SysTick_Config(12000000); 24 | SysTick->VAL = 0; 25 | int ini, fin; 26 | 27 | ini= SysTick->VAL; 28 | crypto_scalarmult_curve25519(sharedSecretCalculatedByAlice, secretKeyAlice, expectedPublicKeyBob); 29 | fin= SysTick->VAL; 30 | 31 | fin = ini-fin; 32 | 33 | sprintf(out, "Cycles: %d.", fin); 34 | print(out); 35 | print("\n"); 36 | 37 | write_byte(4); 38 | 39 | while(1); 40 | } 41 | 42 | void SysTick_Handler(void) 43 | { 44 | ; 45 | } 46 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/layout/fragment_unlock.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 16 | 17 | 23 | 24 | 35 | 36 | -------------------------------------------------------------------------------- /nrf51/app_event_queue.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Key20. 3 | * 4 | * Copyright 2016 Frank Duerr 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "app_event_queue.h" 20 | #include 21 | 22 | void app_event_queue_init(struct app_event_queue *queue) 23 | { 24 | queue->size = APP_EVENT_QUEUE_SIZE; 25 | queue->free = queue->size; 26 | queue->head = 0; 27 | queue->tail = 0; 28 | } 29 | 30 | int app_event_queue_add(struct app_event_queue *queue, struct app_event event) 31 | { 32 | int retval; 33 | 34 | // Add and get functions might be accessed from interrupt context and 35 | // application context concurrently -> need to protect critical sections 36 | // by avoiding context switches (interrupts) in critical section. 37 | CRITICAL_REGION_ENTER(); 38 | if (queue->free == 0) { 39 | retval = -1; 40 | } else { 41 | queue->events[queue->head] = event; 42 | queue->head = (queue->head+1)%queue->size; 43 | queue->free--; 44 | retval = 0; 45 | } 46 | CRITICAL_REGION_EXIT(); 47 | 48 | return retval; 49 | } 50 | 51 | int app_event_queue_get(struct app_event_queue *queue, struct app_event *event) 52 | { 53 | int retval; 54 | 55 | // Add and get functions might be accessed from interrupt context and 56 | // application context concurrently -> need to protect critical sections 57 | // by avoiding context switches (interrupts) in critical section. 58 | CRITICAL_REGION_ENTER(); 59 | if (queue->free == queue->size) { 60 | retval = -1; 61 | } else { 62 | *event = queue->events[queue->tail]; 63 | queue->tail = (queue->tail+1)%queue->size; 64 | queue->free++; 65 | retval = 0; 66 | } 67 | CRITICAL_REGION_EXIT(); 68 | 69 | return retval; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /avrnacl/crypto_auth/hmac.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: avrnacl_8bitc/crypto_auth/hmac.c 3 | * Author: Michael Hutter, Peter Schwabe 4 | * Version: Tue Aug 12 08:23:16 2014 +0200 5 | * Public Domain 6 | */ 7 | 8 | 9 | /* 10 | * Based on crypto_auth/hmacsha512256/ref, version 20080913 11 | * by D. J. Bernstein (Public domain). 12 | * */ 13 | 14 | #include "avrnacl.h" 15 | 16 | #define blocks crypto_hashblocks_sha512 17 | 18 | typedef unsigned long long uint64; 19 | 20 | extern const unsigned char avrnacl_sha512_iv[64]; 21 | 22 | int crypto_auth_hmacsha512256( 23 | unsigned char *out, 24 | const unsigned char *in, crypto_uint16 inlen, 25 | const unsigned char *k 26 | ) 27 | { 28 | unsigned char h[64]; 29 | unsigned char padded[256]; 30 | unsigned int i; 31 | unsigned int bytes = 128 + inlen; 32 | 33 | for (i = 0;i < 64;++i) h[i] = avrnacl_sha512_iv[i]; 34 | 35 | for (i = 0;i < 32;++i) padded[i] = k[i] ^ 0x36; 36 | for (i = 32;i < 128;++i) padded[i] = 0x36; 37 | 38 | blocks(h,padded,128); 39 | blocks(h,in,inlen); 40 | in += inlen; 41 | inlen &= 127; 42 | in -= inlen; 43 | 44 | for (i = 0;i < inlen;++i) padded[i] = in[i]; 45 | padded[inlen] = 0x80; 46 | 47 | if (inlen < 112) { 48 | for (i = inlen + 1;i < 125;++i) padded[i] = 0; 49 | padded[125] = bytes >> 13; 50 | padded[126] = bytes >> 5; 51 | padded[127] = bytes << 3; 52 | blocks(h,padded,128); 53 | } else { 54 | for (i = inlen + 1;i < 253;++i) padded[i] = 0; 55 | padded[253] = bytes >> 13; 56 | padded[254] = bytes >> 5; 57 | padded[255] = bytes << 3; 58 | blocks(h,padded,256); 59 | } 60 | 61 | for (i = 0;i < 32;++i) padded[i] = k[i] ^ 0x5c; 62 | for (i = 32;i < 128;++i) padded[i] = 0x5c; 63 | 64 | for (i = 0;i < 64;++i) padded[128 + i] = h[i]; 65 | for (i = 0;i < 64;++i) h[i] = avrnacl_sha512_iv[i]; 66 | 67 | for (i = 64;i < 128;++i) padded[128 + i] = 0; 68 | padded[128 + 64] = 0x80; 69 | padded[128 + 126] = 6; 70 | 71 | blocks(h,padded,256); 72 | for (i = 0;i < 32;++i) out[i] = h[i]; 73 | 74 | return 0; 75 | } 76 | 77 | 78 | int crypto_auth_hmacsha512256_verify( 79 | const unsigned char *h, 80 | const unsigned char *in,crypto_uint16 inlen, 81 | const unsigned char *k 82 | ) 83 | { 84 | unsigned char correct[32]; 85 | crypto_auth_hmacsha512256(correct,in,inlen,k); 86 | return crypto_verify_32(h,correct); 87 | } 88 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/layout/activity_device_selection.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 17 | 18 | 21 | 22 | 26 | 27 | 35 | 36 | 42 | 43 | 44 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /curve25519-cortexm0/Makefile: -------------------------------------------------------------------------------- 1 | CC= clang 2 | CFLAGS= -fshort-enums -O3 -DCORTEX_M0 -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=cortex-m0 -fno-builtin -ffreestanding -target arm-none-eabi -mfloat-abi=soft -nostdlib -no-integrated-as 3 | ASFLAGS= -mcpu=cortex-m0 -target arm-none-eabi -mfloat-abi=soft -nostdlib -no-integrated-as 4 | INCDIRS=-I./stm32f0xx 5 | AR = arm-none-eabi-ar 6 | 7 | STMOBJ = stm32f0xx/system_stm32f0xx.o \ 8 | stm32f0xx/stm32f0xx_gpio.o \ 9 | stm32f0xx/stm32f0xx_rcc.o \ 10 | stm32f0xx/stm32f0xx_usart.o \ 11 | stm32f0xx/startup_stm32f0xx.o \ 12 | stm32f0xx/sbrk.o 13 | 14 | LINKERFILE = stm32f0xx/stm32f0_linker.ld 15 | 16 | all: test/speed.bin test/test.bin test/stack.bin 17 | 18 | test/speed.elf: $(STMOBJ) test/speed.c test/print.c obj/curve25519.a 19 | $(CC) $(CFLAGS) $(INCDIRS) -T $(LINKERFILE) $(STMOBJ) test/speed.c test/print.c obj/curve25519.a -o $@ 20 | 21 | test/stack.elf: $(STMOBJ) test/stack.c test/print.c obj/curve25519.a 22 | $(CC) $(CFLAGS) $(INCDIRS) -T $(LINKERFILE) $(STMOBJ) test/stack.c test/print.c test/randombytes.c obj/curve25519.a -o $@ 23 | 24 | test/test.elf: $(STMOBJ) test/test.c obj/curve25519.a 25 | $(CC) $(CFLAGS) $(INCDIRS) -T $(LINKERFILE) $(STMOBJ) test/test.c test/print.c test/randombytes.c test/fail.c obj/curve25519.a -o $@ 26 | 27 | 28 | obj/curve25519.a: obj/scalarmult.o \ 29 | obj/cortex_m0_mpy121666.o \ 30 | obj/cortex_m0_reduce25519.o \ 31 | obj/sqr.o \ 32 | obj/mul.o 33 | mkdir -p obj/ 34 | $(AR) -ar cr $@ $^ 35 | 36 | 37 | obj/scalarmult.o: scalarmult.s 38 | mkdir -p obj/ 39 | $(CC) $(ASFLAGS) -c $^ -o $@ 40 | 41 | scalarmult.s: scalarmult_opt.bc 42 | llc -misched=ilpmin -enable-misched -misched-regpressure scalarmult_opt.bc -o scalarmult.s 43 | 44 | scalarmult_opt.bc: scalarmult.c 45 | clang -fshort-enums -mthumb -mcpu=cortex-m0 -emit-llvm -c -nostdlib -ffreestanding -target arm-none-eabi -mfloat-abi=soft scalarmult.c -I /usr/arm-linux-gnueabi/include 46 | opt -Os -inline -misched=ilpmin -enable-misched -misched-regpressure scalarmult.bc -o scalarmult_opt.bc 47 | 48 | %.bin: %.elf 49 | arm-none-eabi-objcopy -O binary $^ $@ 50 | 51 | obj/%.o: %.c 52 | mkdir -p obj/ 53 | $(CC) $(CFLAGS) $(INCDIRS) -c $^ -o $@ 54 | 55 | obj/%.o: %.s 56 | mkdir -p obj/ 57 | $(CC) $(ASFLAGS) -c $^ -o $@ 58 | 59 | stm32f0xx/%.o: stm32f0xx/%.c 60 | $(CC) $(CFLAGS) $(INCDIRS) -c $^ -o $@ 61 | 62 | stm32f0xx/%.o: stm32f0xx/%.s 63 | $(CC) $(ASFLAGS) -c $^ -o $@ 64 | 65 | .PHONY: clean 66 | 67 | clean: 68 | -rm obj/* 69 | -rm scalarmult.s 70 | -rm scalarmult_opt.bc 71 | -rm stm32f0xx/*.o 72 | -rm test/test.elf 73 | -rm test/test.bin 74 | -rm test/speed.elf 75 | -rm test/stack.bin 76 | -rm test/stack.elf 77 | -rm test/speed.bin 78 | -------------------------------------------------------------------------------- /android/Key20/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /curve25519-cortexm0/stm32f0xx/system_stm32f0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 23-March-2012 7 | * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f0xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F0XX_H 40 | #define __SYSTEM_STM32F0XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F0xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F0xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @addtogroup STM32F0xx_System_Exported_Constants 66 | * @{ 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @addtogroup STM32F0xx_System_Exported_Macros 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @addtogroup STM32F0xx_System_Exported_Functions 82 | * @{ 83 | */ 84 | 85 | extern void SystemInit(void); 86 | extern void SystemCoreClockUpdate(void); 87 | /** 88 | * @} 89 | */ 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /*__SYSTEM_STM32F0XX_H */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /android/Key20/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.7 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /curve25519-cortexm0/test/print.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static int uart_initialized = 0; 5 | 6 | static void initUART(){ 7 | USART_InitTypeDef USART_InitStructure; 8 | GPIO_InitTypeDef GPIO_InitStructure; 9 | 10 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); 11 | 12 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); 13 | GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1); 14 | GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1); 15 | 16 | //Configure USART2 pins: Rx and Tx ---------------------------- 17 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; 18 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 19 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 20 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 21 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 22 | GPIO_Init(GPIOA, &GPIO_InitStructure); 23 | 24 | //Configure USART2 setting: ---------------------------- 25 | USART_InitStructure.USART_BaudRate = 9600; 26 | USART_InitStructure.USART_WordLength = USART_WordLength_8b; 27 | USART_InitStructure.USART_StopBits = USART_StopBits_1; 28 | USART_InitStructure.USART_Parity = USART_Parity_No; 29 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 30 | USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; 31 | USART_Init(USART2, &USART_InitStructure); 32 | 33 | USART_Cmd(USART2,ENABLE); 34 | } 35 | 36 | void write_byte(unsigned char c) 37 | { 38 | if(!uart_initialized) 39 | { 40 | initUART(); 41 | uart_initialized = 1; 42 | } 43 | 44 | while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); 45 | USART_SendData(USART2, (unsigned char) c); 46 | } 47 | 48 | void print(const char *in_s) 49 | { 50 | unsigned char lp = 0; 51 | 52 | while(in_s[lp] != 0) 53 | write_byte((unsigned char) in_s[lp++]); 54 | } 55 | 56 | void bigint_print(const unsigned char *x, unsigned char xlen) 57 | { 58 | int i; 59 | char ts[15]; 60 | 61 | print("("); 62 | for(i=xlen-1;i>0;i--) 63 | { 64 | sprintf(ts, "%u*2^(%d*8)+",x[i],i); 65 | print(ts); 66 | } 67 | sprintf(ts, "%u*2^(%d*8))",x[0],i); 68 | print(ts); 69 | } 70 | 71 | void printllu(unsigned long long x) 72 | { 73 | char str[24]; 74 | int i = 22; 75 | str[23]=0; 76 | if(x==0) 77 | print("0"); 78 | while(x>0) 79 | { 80 | str[i] = (char)((x%10)+48); 81 | i--; 82 | x = x/10; 83 | } 84 | print(str+i+1); 85 | } 86 | 87 | 88 | void print_stack(const char *primitive, const unsigned int bytes, unsigned int stack) 89 | { 90 | print(primitive); 91 | print(": "); 92 | if(bytes != (unsigned int)-1) 93 | { 94 | print("["); 95 | printllu(bytes); 96 | print("] "); 97 | } 98 | 99 | printllu(stack); 100 | print(" stack bytes\n"); 101 | } 102 | -------------------------------------------------------------------------------- /android/Key20/app/src/main/res/layout/fragment_keyexchange.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 16 | 17 | 22 | 23 | 29 | 30 | 35 | 36 | 42 | 43 | 52 | 53 |