├── 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 |
5 |
6 |
7 |
8 |
9 |
10 |
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 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
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 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.7
51 |
52 |
53 |
54 |
55 |
56 |
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 |
59 |
60 |
71 |
72 |
--------------------------------------------------------------------------------
/hd44780nrf51/hd44780nrf51.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Frank Duerr
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef HD44780NRF51_H
18 | #define HD44780NRF51_H
19 |
20 | #include
21 |
22 | #ifndef HD44780_2nd_LINE_OFFSET
23 | // The DDRAM memory offset of the second line of the display.
24 | #define HD44780_2nd_LINE_OFFSET 0x40
25 | #endif
26 |
27 | /**
28 | * Pins connected to the LCD.
29 | *
30 | * The LCD is operated in 4-bit mode, thus, pins DB0-3 are not required.
31 | *
32 | * The LCD is time-driven using wait statements rather than testing the
33 | * busy flag. Thus, we do never read from the display and assume that the r/w
34 | * pin of the display has been hard-wired to GND (fixed write mode).
35 | */
36 | struct hd44780 {
37 | unsigned int pin_rs; /**< Register select */
38 | unsigned int pin_e; /**< Read/write start */
39 | unsigned int pin_db4; /**< Data pin 4 */
40 | unsigned int pin_db5; /**< Data pin 5 */
41 | unsigned int pin_db6; /**< Data pin 6 */
42 | unsigned int pin_db7; /**< Data pin 7 */
43 | unsigned int rows; /**< Number of rows (1 or 2) */
44 | unsigned int columns; /**< Number of columns */
45 | };
46 |
47 | /**
48 | * Initialization of the LCD.
49 | *
50 | * @param lcd definition of the LCD display to be used.
51 | */
52 | void hd44780_init(const struct hd44780 *lcd);
53 |
54 | /**
55 | * Turn the display, cursor, and cursor blinking on or off.
56 | *
57 | * @param lcd definition of the LCD display to be used.
58 | * @param display_on if true, turn display on; otherwise turn display off.
59 | * @param cursor_on if true, turn cursor on; otherwise turn cursor off.
60 | * @param cursor_blinking if true, let cursor blink; otherwise turn blinking
61 | * off.
62 | */
63 | void hd44780_display_on_off(const struct hd44780 *lcd, bool display_on,
64 | bool cursor_on, bool cursor_blinking);
65 |
66 | /**
67 | * Prints one line of text.
68 | *
69 | * @param lcd definition of the LCD display to be used.
70 | * @param text text to be printed.
71 | * @param length length of text.
72 | * @param line line (0 or 1) where the text is to be printed.
73 | */
74 | void hd44780_print_line(const struct hd44780 *lcd, const char *text,
75 | unsigned int length, unsigned int line);
76 |
77 | /**
78 | * Clears the whole display.
79 | *
80 | * @param lcd definition of the LCD display to be used.
81 | */
82 | void hd44780_clear_display(const struct hd44780 *lcd);
83 |
84 | /**
85 | * Clears one line if the display by writing spaces to all characters.
86 | *
87 | * @param lcd definition of the LCD display to be used.
88 | * @param line line number (0 or 1) to be cleared.
89 | */
90 | void hd44780_clear_line(const struct hd44780 *lcd, unsigned int line);
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/curve25519-cortexm0/stm32f0xx/stm32f0_linker.ld:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * This linker file was developed by Hussam Al-Hertani. Please use freely as
3 | * long as you leave this header in place. The author is not responsible for any
4 | * damage or liability that this file might cause.
5 | ******************************************************************************/
6 |
7 | /* Entry Point */
8 | ENTRY(Reset_Handler)
9 |
10 | /* Specify the memory areas */
11 | MEMORY
12 | {
13 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x10000 /*64K*/
14 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x02000 /*8K*/
15 | }
16 |
17 | /* define stack size and heap size here */
18 | stack_size = 3072;
19 | heap_size = 0;
20 |
21 | /* define beginning and ending of stack */
22 | _stack_start = ORIGIN(RAM)+LENGTH(RAM);
23 | _stack_end = _stack_start - stack_size;
24 |
25 | /* Define output sections */
26 | SECTIONS
27 | {
28 | /* The startup code goes first into FLASH */
29 | .isr_vector :
30 | {
31 | . = ALIGN(4);
32 | KEEP(*(.isr_vector)) /* Startup code */
33 | . = ALIGN(4);
34 | } >FLASH
35 |
36 | /* The program code and other data goes into FLASH */
37 | .text :
38 | {
39 | . = ALIGN(4);
40 | *(.text) /* .text sections (code) */
41 | *(.text*) /* .text* sections (code) */
42 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
43 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
44 | *(.glue_7) /* glue arm to thumb code */
45 | *(.glue_7t) /* glue thumb to arm code */
46 | . = ALIGN(4);
47 | _etext = .; /* define a global symbols at end of code */
48 | } >FLASH
49 |
50 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
51 | .ARM : {
52 | __exidx_start = .;
53 | *(.ARM.exidx*)
54 | __exidx_end = .;
55 | } >FLASH
56 |
57 | /* used by the startup to initialize data */
58 | _sidata = .;
59 |
60 | /* Initialized data sections goes into RAM, load LMA copy after code */
61 | .data : AT ( _sidata )
62 | {
63 | . = ALIGN(4);
64 | _sdata = .; /* create a global symbol at data start */
65 | *(.data) /* .data sections */
66 | *(.data*) /* .data* sections */
67 |
68 | . = ALIGN(4);
69 | _edata = .; /* define a global symbol at data end */
70 | } >RAM
71 |
72 | /* Uninitialized data section */
73 | . = ALIGN(4);
74 | .bss :
75 | {
76 | /* Used by the startup in order to initialize the .bss secion */
77 | _sbss = .; /* define a global symbol at bss start */
78 | __bss_start__ = _sbss;
79 | *(.bss)
80 | *(.bss*)
81 | *(COMMON)
82 |
83 | . = ALIGN(4);
84 | _ebss = .; /* define a global symbol at bss end */
85 | __bss_end__ = _ebss;
86 | } >RAM
87 |
88 | . = ALIGN(4);
89 | .heap :
90 | {
91 | _heap_start = .;
92 | . = . + heap_size;
93 | _heap_end = .;
94 | } > RAM
95 |
96 |
97 | /* Remove information from the standard libraries */
98 | /DISCARD/ :
99 | {
100 | libc.a ( * )
101 | libm.a ( * )
102 | libgcc.a ( * )
103 | }
104 |
105 | .ARM.attributes 0 : { *(.ARM.attributes) }
106 | }
107 |
--------------------------------------------------------------------------------
/avrnacl/shared/bigint.c:
--------------------------------------------------------------------------------
1 | /*
2 | * File: avrnacl_8bitc/shared/bigint.c
3 | * Author: Michael Hutter, Peter Schwabe
4 | * Version: Tue Aug 12 08:23:16 2014 +0200
5 | * Public Domain
6 | */
7 |
8 | #include "avrnacl.h"
9 | #include "bigint.h"
10 |
11 | unsigned char bigint_add(unsigned char *r, const unsigned char *a, const unsigned char *b, unsigned int len)
12 | {
13 | unsigned int i;
14 | crypto_uint16 tmp = 0;
15 | for (i=0; i>= 8;
20 | }
21 | return (unsigned char)tmp;
22 | }
23 |
24 | unsigned char bigint_sub(unsigned char *r, const unsigned char *a, const unsigned char *b, unsigned int len)
25 | {
26 | unsigned int i;
27 | crypto_uint16 tmp = 0;
28 | for (i=0; i>= 15;
33 | }
34 | return (unsigned char)tmp;
35 | }
36 |
37 | void bigint_mul(unsigned char *r, const unsigned char *a, const unsigned char *b, unsigned int len)
38 | {
39 | unsigned int i,j;
40 | crypto_uint16 t;
41 | for(i=0;i<2*len;i++)
42 | r[i] = 0;
43 |
44 | for (i=0; i>8);
48 | r[i+j]=(t & 0xFF);
49 | }
50 | r[i+len]=(t>>8);
51 | }
52 | }
53 |
54 | static void bigint_mul16c(unsigned char r[34], const unsigned char a[17], const unsigned char b[17])
55 | {
56 | unsigned char t0[9], t1[9],t[18], i;
57 | int u;
58 | bigint_mul(r, a, b, 8);
59 | bigint_mul(r+16, a+8, b+8, 9);
60 |
61 | t0[8] = a[16] + bigint_add(t0,a,a+8,8);
62 | t1[8] = b[16] + bigint_add(t1,b,b+8,8);
63 | bigint_mul(t,t0,t1,9);
64 | t[17] -= bigint_sub(t,t,r+16,17);
65 | u = t[16];
66 | //t[16] -= bigint_sub(t,t,r,16);
67 | u -= bigint_sub(t,t,r,16);
68 | t[16] = u & 0xff;
69 | u>>=15;
70 | t[17] -= u;
71 | u = bigint_add(r+8,r+8,t,17);
72 | for(i=25;i<34;i++)
73 | {
74 | u += r[i];
75 | r[i] = u & 0xff;
76 | u >>= 8;
77 | }
78 | }
79 |
80 | static void bigint_mul16(unsigned char r[32], const unsigned char a[16], const unsigned char b[16])
81 | {
82 | unsigned char t0[9], t1[9],t[18], i;
83 | int u;
84 | bigint_mul(r, a, b, 8);
85 | bigint_mul(r+16, a+8, b+8, 8);
86 | t0[8] = bigint_add(t0,a,a+8,8);
87 | t1[8] = bigint_add(t1,b,b+8,8);
88 | bigint_mul(t,t0,t1,9);
89 | t[16] -= bigint_sub(t,t,r,16);
90 | t[16] -= bigint_sub(t,t,r+16,16);
91 | u = bigint_add(r+8,r+8,t,17);
92 | for(i=25;i<32;i++)
93 | {
94 | u += r[i];
95 | r[i] = u & 0xff;
96 | u >>= 8;
97 | }
98 | }
99 |
100 | void bigint_mul32(unsigned char *r, const unsigned char *a, const unsigned char *b)
101 | {
102 | unsigned char t0[17], t1[17],t[34], i;
103 | int u;
104 | bigint_mul16(r, a, b);
105 | bigint_mul16(r+32, a+16, b+16);
106 | t0[16] = bigint_add(t0,a,a+16,16);
107 | t1[16] = bigint_add(t1,b,b+16,16);
108 | bigint_mul16c(t,t0,t1);
109 | t[32] -= bigint_sub(t,t,r,32);
110 | t[32] -= bigint_sub(t,t,r+32,32);
111 | u = bigint_add(r+16,r+16,t,33);
112 | for(i=49;i<64;i++)
113 | {
114 | u += r[i];
115 | r[i] = u & 0xff;
116 | u >>= 8;
117 | }
118 | }
119 |
120 |
121 | void bigint_cmov(unsigned char *r, const unsigned char *x, unsigned char b, unsigned int len)
122 | {
123 | unsigned int i;
124 | unsigned char mask = b;
125 | mask = -mask;
126 | for(i=0;i© 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 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __STM32F0XX_CONF_H
30 | #define __STM32F0XX_CONF_H
31 |
32 | /* Includes ------------------------------------------------------------------*/
33 | /* Comment the line below to disable peripheral header file inclusion */
34 | //#include "stm32f0xx_adc.h"
35 | //#include "stm32f0xx_cec.h"
36 | //#include "stm32f0xx_crc.h"
37 | //#include "stm32f0xx_comp.h"
38 | //#include "stm32f0xx_dac.h"
39 | //#include "stm32f0xx_dbgmcu.h"
40 | //#include "stm32f0xx_dma.h"
41 | //#include "stm32f0xx_exti.h"
42 | //#include "stm32f0xx_flash.h"
43 | #include "stm32f0xx_gpio.h"
44 | //#include "stm32f0xx_syscfg.h"
45 | //#include "stm32f0xx_i2c.h"
46 | //#include "stm32f0xx_iwdg.h"
47 | //#include "stm32f0xx_pwr.h"
48 | #include "stm32f0xx_rcc.h"
49 | //#include "stm32f0xx_rtc.h"
50 | //#include "stm32f0xx_spi.h"
51 | //#include "stm32f0xx_tim.h"
52 | #include "stm32f0xx_usart.h"
53 | //#include "stm32f0xx_wwdg.h"
54 | //#include "stm32f0xx_misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
55 |
56 | /* Exported types ------------------------------------------------------------*/
57 | /* Exported constants --------------------------------------------------------*/
58 | /* Uncomment the line below to expanse the "assert_param" macro in the
59 | Standard Peripheral Library drivers code */
60 | /* #define USE_FULL_ASSERT 1 */
61 |
62 | /* Exported macro ------------------------------------------------------------*/
63 | #ifdef USE_FULL_ASSERT
64 |
65 | /**
66 | * @brief The assert_param macro is used for function's parameters check.
67 | * @param expr: If expr is false, it calls assert_failed function which reports
68 | * the name of the source file and the source line number of the call
69 | * that failed. If expr is true, it returns no value.
70 | * @retval None
71 | */
72 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
73 | /* Exported functions ------------------------------------------------------- */
74 | void assert_failed(uint8_t* file, uint32_t line);
75 | #else
76 | #define assert_param(expr) ((void)0)
77 | #endif /* USE_FULL_ASSERT */
78 |
79 | #endif /* __STM32F0XX_CONF_H */
80 |
81 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
82 |
--------------------------------------------------------------------------------
/android/Key20/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Key 2.0
3 | Your permission is required
4 | This app needs access to coarse location information to scan for Bluetooth devices.
5 | Scanning for devices …
6 | Scanning stopped
7 | Unlock Door
8 | Key Exchange
9 | Push unlock button to open door.
10 | STEP 1: Select the number of the key that you want to change or create below.
STEP 2: Push the red button on the remote device to start the key exchange procedure.
STEP 3: Click the key exchange button (the button with the key symbol) on the smartphone.
STEP 4: Compare the key checksums displayed on the remote device and on the smartphone.
STEP 5: Only if both devices display the same checksum , push the green button on the remote device and the Confirm Key button on the smartphone to confirm the key. If the checksums differ, push the red button on the remote device.
]]>
11 | Key number:
12 | Key number
13 | Exchange Keys
14 | Confirm Key
15 | Abort
16 | Key checksum:
17 | Start scanning
18 | Scan for Devices
19 | Key 2.0Copyright 2016 Frank Dürr
Licensed under the Apache 2.0 license .
Source code and hardware design are available from Github .
]]>
20 | About
21 | Bluetooth not available
22 | No Bluetooth device selected
23 | Bluetooth connection failure
24 | Bluetooth discovery failure
25 | Required Bluetooth service not available
26 | Required Bluetooth characteristic not available
27 | Bluetooth notifications failure
28 | Timeout while performing Bluetooth task
29 | Bluetooth connection failure
30 | Protocol violation
31 | Could not write Bluetooth characteristic
32 | Invalid key number
33 | No key defined. Please first exchange keys.
34 | There is already another task in progress. Please wait for it to finish.
35 | Please first perform a key exchange
36 | Key confirmed and stored
37 | Door unlocked
38 | IF CHECKSUM IS CORRECT confirm key.
39 |
40 | - Key 1
41 | - Key 2
42 | - Key 3
43 | - Key 4
44 |
45 |
46 |
--------------------------------------------------------------------------------
/nrf51/pstorage_platform.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
2 | *
3 | * The information contained herein is property of Nordic Semiconductor ASA.
4 | * Terms and conditions of usage are described in detail in NORDIC
5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
6 | *
7 | * Licensees are granted free, non-transferable use of the information. NO
8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9 | * the file.
10 | *
11 | */
12 |
13 | /** @cond To make doxygen skip this file */
14 |
15 | /** @file
16 | * This header contains defines with respect persistent storage that are specific to
17 | * persistent storage implementation and application use case.
18 | */
19 | #ifndef PSTORAGE_PL_H__
20 | #define PSTORAGE_PL_H__
21 |
22 | #include
23 | #include "nrf.h"
24 |
25 | static __INLINE uint16_t pstorage_flash_page_size()
26 | {
27 | return (uint16_t)NRF_FICR->CODEPAGESIZE;
28 | }
29 |
30 | #define PSTORAGE_FLASH_PAGE_SIZE pstorage_flash_page_size() /**< Size of one flash page. */
31 | #define PSTORAGE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
32 |
33 | #ifdef NRF51
34 | #define BOOTLOADER_ADDRESS (NRF_UICR->BOOTLOADERADDR)
35 | #elif defined NRF52
36 | #define BOOTLOADER_ADDRESS (PSTORAGE_FLASH_EMPTY_MASK)
37 | #endif
38 |
39 | static __INLINE uint32_t pstorage_flash_page_end()
40 | {
41 | uint32_t bootloader_addr = BOOTLOADER_ADDRESS;
42 |
43 | return ((bootloader_addr != PSTORAGE_FLASH_EMPTY_MASK) ?
44 | (bootloader_addr/ PSTORAGE_FLASH_PAGE_SIZE) : NRF_FICR->CODESIZE);
45 | }
46 |
47 | #define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end()
48 |
49 | #define PSTORAGE_NUM_OF_PAGES 1 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */
50 | #define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */
51 |
52 | #define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
53 | * PSTORAGE_FLASH_PAGE_SIZE) /**< Start address for persistent data, configurable according to system requirements. */
54 | #define PSTORAGE_DATA_END_ADDR ((PSTORAGE_FLASH_PAGE_END - 1) * PSTORAGE_FLASH_PAGE_SIZE) /**< End address for persistent data, configurable according to system requirements. */
55 | #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */
56 |
57 | #define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */
58 | #define PSTORAGE_CMD_QUEUE_SIZE 10 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */
59 |
60 |
61 | /** Abstracts persistently memory block identifier. */
62 | typedef uint32_t pstorage_block_t;
63 |
64 | typedef struct
65 | {
66 | uint32_t module_id; /**< Module ID.*/
67 | pstorage_block_t block_id; /**< Block ID.*/
68 | } pstorage_handle_t;
69 |
70 | typedef uint16_t pstorage_size_t; /** Size of length and offset fields. */
71 |
72 | /**@brief Handles Flash Access Result Events. To be called in the system event dispatcher of the application. */
73 | void pstorage_sys_event_handler (uint32_t sys_evt);
74 |
75 | #endif // PSTORAGE_PL_H__
76 |
77 | /** @} */
78 | /** @endcond */
79 |
--------------------------------------------------------------------------------
/curve25519-cortexm0/cortex_m0_reduce25519.s:
--------------------------------------------------------------------------------
1 | // Implementation of a partial reduction modulo 2^255 - 38.
2 | //
3 | // B. Haase, Endress + Hauser Conducta GmbH & Ko. KG
4 | // public domain.
5 | //
6 | // gnu assembler format.
7 | //
8 | // Generated and tested with C++ functions in the test subdirectory and on the target.
9 | //
10 |
11 | .cpu cortex-m0
12 | .fpu softvfp
13 | .eabi_attribute 20, 1
14 | .eabi_attribute 21, 1
15 | .eabi_attribute 23, 3
16 | .eabi_attribute 24, 1
17 | .eabi_attribute 25, 1
18 | .eabi_attribute 26, 1
19 | .eabi_attribute 30, 2
20 | .eabi_attribute 34, 0
21 | .eabi_attribute 18, 4
22 | .code 16
23 |
24 | .file "cortex_m0_reduce25519.s"
25 |
26 | .text
27 | .align 2
28 |
29 | .global fe25519_reduceTo256Bits_asm
30 | .code 16
31 | .thumb_func
32 | .type fe25519_reduceTo256Bits_asm, %function
33 |
34 | fe25519_reduceTo256Bits_asm:
35 | push {r4,r5,r6,r7,r14}
36 | ldr r2,[r1,#60]
37 | lsr r3,r2,#16
38 | uxth r2,r2
39 | mov r7,#38
40 | mul r2,r7
41 | mul r3,r7
42 | ldr r4,[r1,#28]
43 | lsr r5,r3,#16
44 | lsl r3,r3,#16
45 | mov r6,#0
46 | add r4,r2
47 | adc r5,r6
48 | add r4,r3
49 | adc r5,r6
50 | lsl r2,r4,#1
51 | lsr r2,r2,#1
52 | str r2,[r0,#28]
53 | lsr r4,r4,#31
54 | lsl r5,r5,#1
55 | orr r4,r5
56 | mov r2,#19
57 | mul r2,r4
58 | ldr r4,[r1,#0]
59 | add r2,r4
60 | mov r3,#0
61 | adc r3,r6
62 | ldr r4,[r1,#32]
63 | lsr r5,r4,#16
64 | uxth r4,r4
65 | mul r5,r7
66 | mul r4,r7
67 | add r2,r4
68 | adc r3,r6
69 | lsl r4,r5,#16
70 | lsr r5,r5,#16
71 | add r2,r4
72 | adc r3,r5
73 | str r2,[r0,#0]
74 | ldr r4,[r1,#4]
75 | add r3,r4
76 | mov r2,#0
77 | adc r2,r6
78 | ldr r4,[r1,#36]
79 | lsr r5,r4,#16
80 | uxth r4,r4
81 | mul r5,r7
82 | mul r4,r7
83 | add r3,r4
84 | adc r2,r6
85 | lsl r4,r5,#16
86 | lsr r5,r5,#16
87 | add r3,r4
88 | adc r2,r5
89 | str r3,[r0,#4]
90 | ldr r4,[r1,#8]
91 | add r2,r4
92 | mov r3,#0
93 | adc r3,r6
94 | ldr r4,[r1,#40]
95 | lsr r5,r4,#16
96 | uxth r4,r4
97 | mul r5,r7
98 | mul r4,r7
99 | add r2,r4
100 | adc r3,r6
101 | lsl r4,r5,#16
102 | lsr r5,r5,#16
103 | add r2,r4
104 | adc r3,r5
105 | str r2,[r0,#8]
106 | ldr r4,[r1,#12]
107 | add r3,r4
108 | mov r2,#0
109 | adc r2,r6
110 | ldr r4,[r1,#44]
111 | lsr r5,r4,#16
112 | uxth r4,r4
113 | mul r5,r7
114 | mul r4,r7
115 | add r3,r4
116 | adc r2,r6
117 | lsl r4,r5,#16
118 | lsr r5,r5,#16
119 | add r3,r4
120 | adc r2,r5
121 | str r3,[r0,#12]
122 | ldr r4,[r1,#16]
123 | add r2,r4
124 | mov r3,#0
125 | adc r3,r6
126 | ldr r4,[r1,#48]
127 | lsr r5,r4,#16
128 | uxth r4,r4
129 | mul r5,r7
130 | mul r4,r7
131 | add r2,r4
132 | adc r3,r6
133 | lsl r4,r5,#16
134 | lsr r5,r5,#16
135 | add r2,r4
136 | adc r3,r5
137 | str r2,[r0,#16]
138 | ldr r4,[r1,#20]
139 | add r3,r4
140 | mov r2,#0
141 | adc r2,r6
142 | ldr r4,[r1,#52]
143 | lsr r5,r4,#16
144 | uxth r4,r4
145 | mul r5,r7
146 | mul r4,r7
147 | add r3,r4
148 | adc r2,r6
149 | lsl r4,r5,#16
150 | lsr r5,r5,#16
151 | add r3,r4
152 | adc r2,r5
153 | str r3,[r0,#20]
154 | ldr r4,[r1,#24]
155 | add r2,r4
156 | mov r3,#0
157 | adc r3,r6
158 | ldr r4,[r1,#56]
159 | lsr r5,r4,#16
160 | uxth r4,r4
161 | mul r5,r7
162 | mul r4,r7
163 | add r2,r4
164 | adc r3,r6
165 | lsl r4,r5,#16
166 | lsr r5,r5,#16
167 | add r2,r4
168 | adc r3,r5
169 | str r2,[r0,#24]
170 | ldr r4,[r0,#28]
171 | add r4,r3
172 | str r4,[r0,#28]
173 | pop {r4,r5,r6,r7,r15}
174 |
175 | .size fe25519_reduceTo256Bits_asm, .-fe25519_reduceTo256Bits_asm
176 |
177 |
--------------------------------------------------------------------------------
/curve25519-cortexm0/cortex_m0_mpy121666.s:
--------------------------------------------------------------------------------
1 | // Implementation of multiplication of an fe25519 bit value with the curve constant 121666.
2 | //
3 | // B. Haase, Endress + Hauser Conducta GmbH & Ko. KG
4 | // public domain.
5 | //
6 | // gnu assembler format.
7 | //
8 | // Generated and tested with C++ functions in the test subdirectory.
9 | //
10 | // ATTENTION:
11 | // Not yet tested on target hardware.
12 |
13 |
14 | .cpu cortex-m0
15 | .fpu softvfp
16 | .eabi_attribute 20, 1
17 | .eabi_attribute 21, 1
18 | .eabi_attribute 23, 3
19 | .eabi_attribute 24, 1
20 | .eabi_attribute 25, 1
21 | .eabi_attribute 26, 1
22 | .eabi_attribute 30, 2
23 | .eabi_attribute 34, 0
24 | .eabi_attribute 18, 4
25 | .code 16
26 |
27 | .file "cortex_m0_reduce25519.s"
28 |
29 | .text
30 | .align 2
31 |
32 | .global fe25519_mpyWith121666_asm
33 | .code 16
34 | .thumb_func
35 | .type fe25519_mpyWith121666_asm, %function
36 |
37 | fe25519_mpyWith121666_asm:
38 | push {r4,r5,r6,r7,r14}
39 | ldr r7,__label_for_immediate_56130
40 | ldr r2,[r1,#28]
41 | lsl r5,r2,#16
42 | lsr r6,r2,#16
43 | lsr r3,r2,#16
44 | uxth r2,r2
45 | mul r2,r7
46 | mul r3,r7
47 | add r5,r2
48 | mov r2,#0
49 | adc r6,r2
50 | lsl r2,r3,#16
51 | lsr r3,r3,#16
52 | add r5,r2
53 | adc r6,r3
54 | lsl r2,r5,#1
55 | lsr r2,r2,#1
56 | str r2,[r0,#28]
57 | lsr r5,r5,#31
58 | lsl r6,r6,#1
59 | orr r5,r6
60 | mov r6,#19
61 | mul r5,r6
62 | mov r6,#0
63 | ldr r2,[r1,#0]
64 | lsl r3,r2,#16
65 | lsr r4,r2,#16
66 | add r5,r3
67 | adc r6,r4
68 | lsr r3,r2,#16
69 | uxth r2,r2
70 | mul r2,r7
71 | mul r3,r7
72 | add r5,r2
73 | mov r2,#0
74 | adc r6,r2
75 | lsl r2,r3,#16
76 | lsr r3,r3,#16
77 | add r5,r2
78 | adc r6,r3
79 | str r5,[r0,#0]
80 | mov r5,#0
81 | ldr r2,[r1,#4]
82 | lsl r3,r2,#16
83 | lsr r4,r2,#16
84 | add r6,r3
85 | adc r5,r4
86 | lsr r3,r2,#16
87 | uxth r2,r2
88 | mul r2,r7
89 | mul r3,r7
90 | add r6,r2
91 | mov r2,#0
92 | adc r5,r2
93 | lsl r2,r3,#16
94 | lsr r3,r3,#16
95 | add r6,r2
96 | adc r5,r3
97 | str r6,[r0,#4]
98 | mov r6,#0
99 | ldr r2,[r1,#8]
100 | lsl r3,r2,#16
101 | lsr r4,r2,#16
102 | add r5,r3
103 | adc r6,r4
104 | lsr r3,r2,#16
105 | uxth r2,r2
106 | mul r2,r7
107 | mul r3,r7
108 | add r5,r2
109 | mov r2,#0
110 | adc r6,r2
111 | lsl r2,r3,#16
112 | lsr r3,r3,#16
113 | add r5,r2
114 | adc r6,r3
115 | str r5,[r0,#8]
116 | mov r5,#0
117 | ldr r2,[r1,#12]
118 | lsl r3,r2,#16
119 | lsr r4,r2,#16
120 | add r6,r3
121 | adc r5,r4
122 | lsr r3,r2,#16
123 | uxth r2,r2
124 | mul r2,r7
125 | mul r3,r7
126 | add r6,r2
127 | mov r2,#0
128 | adc r5,r2
129 | lsl r2,r3,#16
130 | lsr r3,r3,#16
131 | add r6,r2
132 | adc r5,r3
133 | str r6,[r0,#12]
134 | mov r6,#0
135 | ldr r2,[r1,#16]
136 | lsl r3,r2,#16
137 | lsr r4,r2,#16
138 | add r5,r3
139 | adc r6,r4
140 | lsr r3,r2,#16
141 | uxth r2,r2
142 | mul r2,r7
143 | mul r3,r7
144 | add r5,r2
145 | mov r2,#0
146 | adc r6,r2
147 | lsl r2,r3,#16
148 | lsr r3,r3,#16
149 | add r5,r2
150 | adc r6,r3
151 | str r5,[r0,#16]
152 | mov r5,#0
153 | ldr r2,[r1,#20]
154 | lsl r3,r2,#16
155 | lsr r4,r2,#16
156 | add r6,r3
157 | adc r5,r4
158 | lsr r3,r2,#16
159 | uxth r2,r2
160 | mul r2,r7
161 | mul r3,r7
162 | add r6,r2
163 | mov r2,#0
164 | adc r5,r2
165 | lsl r2,r3,#16
166 | lsr r3,r3,#16
167 | add r6,r2
168 | adc r5,r3
169 | str r6,[r0,#20]
170 | mov r6,#0
171 | ldr r2,[r1,#24]
172 | lsl r3,r2,#16
173 | lsr r4,r2,#16
174 | add r5,r3
175 | adc r6,r4
176 | lsr r3,r2,#16
177 | uxth r2,r2
178 | mul r2,r7
179 | mul r3,r7
180 | add r5,r2
181 | mov r2,#0
182 | adc r6,r2
183 | lsl r2,r3,#16
184 | lsr r3,r3,#16
185 | add r5,r2
186 | adc r6,r3
187 | str r5,[r0,#24]
188 | mov r5,#0
189 | ldr r2,[r0,#28]
190 | add r6,r2
191 | str r6,[r0,#28]
192 | pop {r4,r5,r6,r7,r15}
193 |
194 | .align 2
195 | __label_for_immediate_56130:
196 | .word 56130
197 |
198 | .size fe25519_mpyWith121666_asm, .-fe25519_mpyWith121666_asm
199 |
200 |
--------------------------------------------------------------------------------
/nrf51/Makefile:
--------------------------------------------------------------------------------
1 | NRF51_SDK = /home/duerrfk/local/nRF51_SDK_10.0.0
2 | CURVE25519 = ../curve25519-cortexm0
3 | AVRNACL = ../avrnacl
4 | HD44780NRF51 = ../hd44780nrf51
5 |
6 | CROSS = /usr/local/gcc-arm-none-eabi-5_2-2015q4/bin/arm-none-eabi-
7 |
8 | SRC += key20.c
9 | SRC += app_event_queue.c
10 | SRC += $(NRF51_SDK)/components/toolchain/system_nrf51.c
11 | SRC += $(NRF51_SDK)/components/drivers_nrf/delay/nrf_delay.c
12 | SRC += $(NRF51_SDK)/components/softdevice/common/softdevice_handler/softdevice_handler.c
13 | SRC += $(NRF51_SDK)/components/libraries/util/app_error.c
14 | SRC += $(NRF51_SDK)/components/ble/common/ble_advdata.c
15 | SRC += $(NRF51_SDK)/components/libraries/button/app_button.c
16 | SRC += $(NRF51_SDK)/components/libraries/timer/app_timer.c
17 | SRC += $(NRF51_SDK)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c
18 | SRC += $(NRF51_SDK)/components/drivers_nrf/common/nrf_drv_common.c
19 | SRC += $(NRF51_SDK)/components/drivers_nrf/pstorage/pstorage.c
20 | SRC += $(CURVE25519)/scalarmult.c
21 | SRC += $(AVRNACL)/crypto_hash/sha512.c
22 | SRC += $(AVRNACL)/crypto_hashblocks/sha512.c
23 | SRC += $(AVRNACL)/crypto_auth/hmac.c
24 | SRC += $(AVRNACL)/crypto_verify/verify.c
25 | SRC += $(AVRNACL)/shared/consts.c
26 | SRC += $(AVRNACL)/shared/bigint.c
27 | SRC += $(HD44780NRF51)/hd44780nrf51.c
28 |
29 | #ASM_SRC = $(NRF51_SDK)/components/toolchain/gcc/gcc_startup_nrf51.s
30 | ASM_SRC = gcc_startup_nrf51.s
31 | ASM_SRC += $(CURVE25519)/cortex_m0_mpy121666.s
32 | ASM_SRC += $(CURVE25519)/cortex_m0_reduce25519.s
33 | ASM_SRC += $(CURVE25519)/mul.s
34 | ASM_SRC += $(CURVE25519)/sqr.s
35 |
36 | OUTPUT = key20
37 |
38 | TEMPLATE_PATH = $(NRF51_SDK)/components/toolchain/gcc
39 |
40 | INCLUDES += -I.
41 | INCLUDES += -I$(NRF51_SDK)/components/device
42 | INCLUDES += -I$(NRF51_SDK)/components/drivers_nrf/delay
43 | INCLUDES += -I$(NRF51_SDK)/components/toolchain
44 | INCLUDES += -I$(NRF51_SDK)/components/toolchain/gcc
45 | INCLUDES += -I$(NRF51_SDK)/components/drivers_nrf/hal
46 | INCLUDES += -I$(NRF51_SDK)/components/softdevice/s110/headers
47 | INCLUDES += -I$(NRF51_SDK)/components/softdevice/common/softdevice_handler
48 | INCLUDES += -I$(NRF51_SDK)/components/libraries/util
49 | INCLUDES += -I$(NRF51_SDK)/components/ble/common
50 | INCLUDES += -I$(NRF51_SDK)/components/libraries/timer
51 | INCLUDES += -I$(NRF51_SDK)/components/libraries/button
52 | INCLUDES += -I$(NRF51_SDK)/components/drivers_nrf/gpiote
53 | INCLUDES += -I$(NRF51_SDK)/components/drivers_nrf/config
54 | INCLUDES += -I$(NRF51_SDK)/components/drivers_nrf/common
55 | INCLUDES += -I$(NRF51_SDK)/components/drivers_nrf/pstorage
56 | INCLUDES += -I$(CURVE25519)
57 | INCLUDES += -I$(AVRNACL)
58 | INCLUDES += -I$(AVRNACL)/include
59 | INCLUDES += -I$(HD44780NRF51)
60 |
61 | C_OBJ = $(SRC:.c=.o)
62 | ASM_OBJ = $(ASM_SRC:.s=.o)
63 |
64 | OPTIMIZATION = -O0
65 |
66 | CC = $(CROSS)gcc
67 | LD = $(CROSS)ld
68 | OBJCOPY = $(CROSS)objcopy
69 |
70 | # For nRF51 DK, select nrf51422_ac_s100.ld.
71 | # For productive version using nRF51822, select nrf51822_aa_s110.ld.
72 | #LINKER_SCRIPT = nrf51422_ac_s110.ld
73 | LINKER_SCRIPT = nrf51822_aa_s110.ld
74 |
75 | CFLAGS += -mcpu=cortex-m0 -mthumb -mabi=aapcs -mfloat-abi=soft
76 | CFLAGS += --std=gnu99
77 | # The following options enable the linker to remove unused functions.
78 | CFLAGS += -ffunction-sections -fdata-sections
79 | CFLAGS += -fno-strict-aliasing
80 | CFLAGS += -Wall
81 | CFLAGS += -fno-builtin --short-enums
82 | CFLAGS += $(OPTIMIZATION) $(INCLUDES)
83 | CFLAGS += -DNRF51
84 | CFLAGS += -DBLE_STACK_SUPPORT_REQD
85 | # Set the following definition to compile for the nRF51 DK.
86 | # Otherwise, we compile for the Key20 board.
87 | CFLAGS += -DTARGET_BOARD_NRF51DK
88 | CFLAGS += -DSOFTDEVICE_PRESENT
89 |
90 | ASMFLAGS += -x assembler-with-cpp -mcpu=cortex-m0 -mthumb -mabi=aapcs -mfloat-abi=soft
91 |
92 | LDFLAGS += -Xlinker -Map=$(OUTPUT).map
93 | LDFLAGS += -mcpu=cortex-m0 -mthumb -mabi=aapcs
94 | LDFLAGS += -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
95 | # Let linker remove unused sections
96 | LDFLAGS += -Wl,--gc-sections
97 | # Use newlib in nano version
98 | LDFLAGS += --specs=nano.specs
99 | LDFLAGS += -lc -lnosys
100 |
101 | all: $(OUTPUT).hex
102 |
103 | # Build objects from C source code
104 | $(C_OBJ): %.o: %.c
105 | $(CC) $(CFLAGS) -c $< -o $@
106 |
107 | # Build objects from assembler code
108 | $(ASM_OBJ): %.o: %.s
109 | $(CC) $(ASMFLAGS) -c $< -o $@
110 |
111 | # Link
112 | $(OUTPUT).out: $(C_OBJ) $(ASM_OBJ)
113 | $(CC) $(LDFLAGS) $(C_OBJ) $(ASM_OBJ) -o $@
114 |
115 | # Create binary .hex file from the .out file
116 | $(OUTPUT).hex: $(OUTPUT).out
117 | $(OBJCOPY) -O ihex $< $@
118 |
119 | .PHONY: clean
120 | clean:
121 | rm $(OUTPUT).hex $(OUTPUT).out $(ASM_OBJ) $(C_OBJ)
122 |
--------------------------------------------------------------------------------
/curve25519-cortexm0/test/test.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Based on crypto_scalarmult/try.c version 20090118 by D. J. Bernstein
3 | * Public domain.
4 | */
5 |
6 | #include
7 | #include "../api.h"
8 | #include "print.h"
9 | #include "fail.h"
10 | #include "randombytes.h"
11 |
12 |
13 | #define mlen crypto_scalarmult_SCALARBYTES
14 | #define nlen crypto_scalarmult_SCALARBYTES
15 | #define plen crypto_scalarmult_BYTES
16 | #define qlen crypto_scalarmult_BYTES
17 | #define rlen crypto_scalarmult_BYTES
18 |
19 |
20 | static unsigned char gm[mlen+32];
21 | static unsigned char gn[nlen+32];
22 | static unsigned char gp[plen+32];
23 | static unsigned char gq[qlen+32];
24 | static unsigned char gr[rlen+32];
25 |
26 | static unsigned char gm2[mlen+32];
27 | static unsigned char gn2[nlen+32];
28 | static unsigned char gp2[plen+32];
29 | static unsigned char gq2[qlen+32];
30 | static unsigned char gr2[rlen+32];
31 |
32 | unsigned char *m = gm;
33 | unsigned char *n = gn;
34 | unsigned char *p = gp;
35 | unsigned char *q = gq;
36 | unsigned char *r = gr;
37 |
38 | unsigned char *m2 = gm2;
39 | unsigned char *n2 = gn2;
40 | unsigned char *p2 = gp2;
41 | unsigned char *q2 = gq2;
42 | unsigned char *r2 = gr2;
43 |
44 |
45 | static char checksum[crypto_scalarmult_BYTES * 2 + 1];
46 |
47 | static const unsigned char badn[32] = {0x56,0x2c,0x1e,0xb5,0xfd,0xb2,0x81,0x29,
48 | 0xbd,0x37,0x49,0x58,0x35,0xd4,0xb1,0x30,
49 | 0x7d,0xdb,0x57,0x38,0x80,0x12,0x17,0x42,
50 | 0xf7,0x13,0xf1,0x05,0x67,0x69,0xd5,0xbf};
51 |
52 |
53 |
54 | int main(void)
55 | {
56 | long long i;
57 | long long j;
58 | long long tests;
59 |
60 | m += 16;
61 | n += 16;
62 | p += 16;
63 | q += 16;
64 | r += 16;
65 | m2 += 16;
66 | n2 += 16;
67 | p2 += 16;
68 | q2 += 16;
69 | r2 += 16;
70 |
71 | for (i = 0;i < mlen;++i) m[i] = i;
72 | for (i = 0;i < nlen;++i) n[i] = i + 1;
73 | for (i = 0;i < plen;++i) p[i] = i + 2;
74 | for (i = 0;i < qlen;++i) q[i] = i + 3;
75 | for (i = 0;i < rlen;++i) r[i] = i + 4;
76 |
77 | randombytes(p-16,16);
78 | randombytes(n-16,16);
79 | randombytes(p+plen,16);
80 | randombytes(n+nlen,16);
81 | for (i = -16;i < plen + 16;++i) p2[i] = p[i];
82 | for (i = -16;i < nlen + 16;++i) n2[i] = n[i];
83 |
84 | if (crypto_scalarmult_base(p,n) != 0) fail("crypto_scalarmult_base returns nonzero");
85 |
86 | for (i = -16;i < nlen + 16;++i) if (n2[i] != n[i]) fail("crypto_scalarmult_base overwrites input");
87 | for (i = -16;i < 0;++i) if (p2[i] != p[i]) fail("crypto_scalarmult_base writes before output");
88 | for (i = plen;i < plen + 16;++i) if (p2[i] != p[i]) fail("crypto_scalarmult_base writes after output");
89 |
90 | crypto_scalarmult_base(p,badn);
91 |
92 | for (tests = 0;tests < 5;++tests)
93 | {
94 | randombytes(p-16,16);
95 | randombytes(q-16,16);
96 | randombytes(m-16,16);
97 | randombytes(p+plen,16);
98 | randombytes(q+qlen,16);
99 | randombytes(m+mlen,16);
100 | for (i = -16;i < qlen + 16;++i) q2[i] = q[i];
101 | for (i = -16;i < plen + 16;++i) p2[i] = p[i];
102 | for (i = -16;i < mlen + 16;++i) m2[i] = m[i];
103 |
104 | if (crypto_scalarmult(q,m,p) != 0) fail("crypto_scalarmult returns nonzero");
105 |
106 | for (i = -16;i < mlen + 16;++i) if (m2[i] != m[i]) fail("crypto_scalarmult overwrites n input");
107 | for (i = -16;i < plen + 16;++i) if (p2[i] != p[i]) fail("crypto_scalarmult overwrites p input");
108 | for (i = -16;i < 0;++i) if (q2[i] != q[i]) fail("crypto_scalarmult writes before output");
109 | for (i = qlen;i < qlen + 16;++i) if (q2[i] != q[i]) fail("crypto_scalarmult writes after output");
110 |
111 | if (crypto_scalarmult(m2,m2,p) != 0) fail("crypto_scalarmult returns nonzero");
112 | for (i = 0;i < qlen;++i) if (q[i] != m2[i]) fail("crypto_scalarmult does not handle n overlap");
113 | for (i = 0;i < qlen;++i) m2[i] = m[i];
114 |
115 | if (crypto_scalarmult(p2,m2,p2) != 0) fail("crypto_scalarmult returns nonzero");
116 | for (i = 0;i < qlen;++i) if (q[i] != p2[i]) fail("crypto_scalarmult does not handle p overlap");
117 |
118 | if (crypto_scalarmult(r,n,q) != 0) fail("crypto_scalarmult returns nonzero");
119 | if (crypto_scalarmult(q,n,p) != 0) fail("crypto_scalarmult returns nonzero");
120 | if (crypto_scalarmult(p,m,q) != 0) fail("crypto_scalarmult returns nonzero");
121 | for (j = 0;j < plen;++j) if (p[j] != r[j]) fail("crypto_scalarmult not associative");
122 | for (j = 0;j < mlen;++j) m[j] ^= q[j % qlen];
123 | for (j = 0;j < nlen;++j) n[j] ^= p[j % plen];
124 | }
125 |
126 | for (i = 0;i < crypto_scalarmult_BYTES;++i) {
127 | checksum[2 * i] = "0123456789abcdef"[15 & (p[i] >> 4)];
128 | checksum[2 * i + 1] = "0123456789abcdef"[15 & p[i]];
129 | }
130 | checksum[2 * i] = 0;
131 |
132 | print(checksum);
133 | print("\n");
134 |
135 | write_byte(4);
136 |
137 | while(1);
138 | }
139 |
--------------------------------------------------------------------------------
/android/Key20/app/src/main/java/de/frank_durr/key20/UnlockFragment.java:
--------------------------------------------------------------------------------
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 | package de.frank_durr.key20;
20 |
21 | import android.app.Activity;
22 | import android.os.Bundle;
23 | import android.os.Handler;
24 | import android.os.Message;
25 | import android.support.design.widget.FloatingActionButton;
26 | import android.support.v4.app.Fragment;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.widget.ProgressBar;
31 |
32 | import java.lang.ref.WeakReference;
33 |
34 | /**
35 | * Fragment displaying the UI for unlocking a door.
36 | */
37 | public class UnlockFragment extends Fragment {
38 |
39 | private FloatingActionButton floatingActionButton;
40 | private ProgressBar progressBar;
41 |
42 | private WeakReference activity;
43 |
44 | public MessageHandler msgHandler;
45 |
46 | /**
47 | * Use this factory method to create a new instance of
48 | * this fragment using the provided parameters.
49 | *
50 | * @return A new instance of fragment UnlockFragment.
51 | */
52 | public static UnlockFragment newInstance() {
53 | UnlockFragment fragment = new UnlockFragment();
54 |
55 | Bundle args = new Bundle();
56 | fragment.setArguments(args);
57 |
58 | return fragment;
59 | }
60 |
61 | /**
62 | * Handler for messages to the fragment.
63 | *
64 | * The handler runs in the UI thread.
65 | *
66 | * We make this class a static nested class, so a reference to the message handler (and
67 | * pending messages obtained from this handler) will not prevent the outer class from being
68 | * garbage-collected through a strong reference from a (non-static) inner to its outer class.
69 | * There is no point in keeping the fragment alive just to receive pending messages, which are
70 | * anyway not handled anymore by a "dead" fragment.
71 | */
72 | public static class MessageHandler extends Handler {
73 | public final static int TASK_STARTED = 0;
74 | public final static int TASK_FINISHED = 1;
75 |
76 | private final WeakReference fragment;
77 |
78 | public MessageHandler(UnlockFragment fragment) {
79 | this.fragment = new WeakReference(fragment);
80 | }
81 |
82 | @Override
83 | public void handleMessage(Message message) {
84 | // Get a strong reference to the fragment.
85 | UnlockFragment f = fragment.get();
86 | if (f == null) {
87 | // The fragment has been garbage-collected.
88 | return;
89 | }
90 |
91 | switch (message.what) {
92 | case TASK_STARTED :
93 | f.progressBar.setVisibility(View.VISIBLE);
94 | break;
95 | case TASK_FINISHED :
96 | f.progressBar.setVisibility(View.INVISIBLE);
97 | break;
98 | }
99 | }
100 | }
101 |
102 | /**
103 | * An empty constructor is required.
104 | */
105 | public UnlockFragment() {
106 | }
107 |
108 | @Override
109 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
110 | Bundle savedInstanceState) {
111 | // Inflate the layout for this fragment
112 | View v = inflater.inflate(R.layout.fragment_unlock, container, false);
113 |
114 | progressBar = (ProgressBar) v.findViewById(R.id.progressbar_unlock);
115 | progressBar.setVisibility(View.INVISIBLE);
116 |
117 | floatingActionButton = (FloatingActionButton) v.findViewById(R.id.fab_unlock);
118 | floatingActionButton.setOnClickListener(new View.OnClickListener() {
119 | @Override public void onClick(View v) {
120 | // Get a strong reference to the activity.
121 | MainActivity activity = UnlockFragment.this.activity.get();
122 | if (activity == null) {
123 | // The activity has already been garbage collected.
124 | return;
125 | }
126 |
127 | Message msg;
128 | msg = activity.applicationEventHandler.obtainMessage(
129 | MainActivity.ApplicationEventHandler.START_DOOR_UNLOCK);
130 | activity.applicationEventHandler.sendMessage(msg);
131 | }
132 | });
133 |
134 | msgHandler = new MessageHandler(this);
135 |
136 | return v;
137 | }
138 |
139 | @Override
140 | public void onAttach(Activity activity) {
141 | super.onAttach(activity);
142 | this.activity = new WeakReference((MainActivity) activity);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/android/Key20/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/curve25519-cortexm0/cc0_1.0:
--------------------------------------------------------------------------------
1 |
2 | Creative Commons CC0 1.0 Universal
3 |
4 | Statement of Purpose
5 |
6 | The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
7 |
8 | Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
9 |
10 | For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
11 |
12 | 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
13 |
14 | the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
15 | moral rights retained by the original author(s) and/or performer(s);
16 | publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
17 | rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
18 | rights protecting the extraction, dissemination, use and reuse of data in a Work;
19 | database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
20 | other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
21 |
22 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
23 |
24 | 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
25 |
26 | 4. Limitations and Disclaimers.
27 |
28 | No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
29 | Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
30 | Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
31 | Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
32 |
33 |
34 |
--------------------------------------------------------------------------------
/nrf51/gcc_startup_nrf51.s:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015, Nordic Semiconductor ASA
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | * Redistributions in binary form must reproduce the above copyright notice,
12 | this list of conditions and the following disclaimer in the documentation
13 | and/or other materials provided with the distribution.
14 |
15 | * Neither the name of Nordic Semiconductor ASA nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | /*
32 | NOTE: Template files (including this one) are application specific and therefore
33 | expected to be copied into the application project folder prior to its use!
34 | */
35 |
36 | .syntax unified
37 | .arch armv6-m
38 |
39 | .section .stack
40 | .align 3
41 | #ifdef __STACK_SIZE
42 | .equ Stack_Size, __STACK_SIZE
43 | #else
44 | .equ Stack_Size, 3584
45 | #endif
46 | .globl __StackTop
47 | .globl __StackLimit
48 | __StackLimit:
49 | .space Stack_Size
50 | .size __StackLimit, . - __StackLimit
51 | __StackTop:
52 | .size __StackTop, . - __StackTop
53 |
54 | .section .heap
55 | .align 3
56 | #ifdef __HEAP_SIZE
57 | .equ Heap_Size, __HEAP_SIZE
58 | #else
59 | .equ Heap_Size, 512
60 | #endif
61 | .globl __HeapBase
62 | .globl __HeapLimit
63 | __HeapBase:
64 | .if Heap_Size
65 | .space Heap_Size
66 | .endif
67 | .size __HeapBase, . - __HeapBase
68 | __HeapLimit:
69 | .size __HeapLimit, . - __HeapLimit
70 |
71 | .section .Vectors
72 | .align 2
73 | .globl __Vectors
74 | __Vectors:
75 | .long __StackTop /* Top of Stack */
76 | .long Reset_Handler
77 | .long NMI_Handler
78 | .long HardFault_Handler
79 | .long 0 /*Reserved */
80 | .long 0 /*Reserved */
81 | .long 0 /*Reserved */
82 | .long 0 /*Reserved */
83 | .long 0 /*Reserved */
84 | .long 0 /*Reserved */
85 | .long 0 /*Reserved */
86 | .long SVC_Handler
87 | .long 0 /*Reserved */
88 | .long 0 /*Reserved */
89 | .long PendSV_Handler
90 | .long SysTick_Handler
91 |
92 | /* External Interrupts */
93 | .long POWER_CLOCK_IRQHandler
94 | .long RADIO_IRQHandler
95 | .long UART0_IRQHandler
96 | .long SPI0_TWI0_IRQHandler
97 | .long SPI1_TWI1_IRQHandler
98 | .long 0 /*Reserved */
99 | .long GPIOTE_IRQHandler
100 | .long ADC_IRQHandler
101 | .long TIMER0_IRQHandler
102 | .long TIMER1_IRQHandler
103 | .long TIMER2_IRQHandler
104 | .long RTC0_IRQHandler
105 | .long TEMP_IRQHandler
106 | .long RNG_IRQHandler
107 | .long ECB_IRQHandler
108 | .long CCM_AAR_IRQHandler
109 | .long WDT_IRQHandler
110 | .long RTC1_IRQHandler
111 | .long QDEC_IRQHandler
112 | .long LPCOMP_IRQHandler
113 | .long SWI0_IRQHandler
114 | .long SWI1_IRQHandler
115 | .long SWI2_IRQHandler
116 | .long SWI3_IRQHandler
117 | .long SWI4_IRQHandler
118 | .long SWI5_IRQHandler
119 | .long 0 /*Reserved */
120 | .long 0 /*Reserved */
121 | .long 0 /*Reserved */
122 | .long 0 /*Reserved */
123 | .long 0 /*Reserved */
124 | .long 0 /*Reserved */
125 |
126 | .size __Vectors, . - __Vectors
127 |
128 | /* Reset Handler */
129 |
130 | .equ NRF_POWER_RAMON_ADDRESS, 0x40000524
131 | .equ NRF_POWER_RAMONB_ADDRESS, 0x40000554
132 | .equ NRF_POWER_RAMONx_RAMxON_ONMODE_Msk, 0x3
133 |
134 | .text
135 | .thumb
136 | .thumb_func
137 | .align 1
138 | .globl Reset_Handler
139 | .type Reset_Handler, %function
140 | Reset_Handler:
141 | .fnstart
142 |
143 | /* Make sure ALL RAM banks are powered on */
144 | MOVS R1, #NRF_POWER_RAMONx_RAMxON_ONMODE_Msk
145 |
146 | LDR R0, =NRF_POWER_RAMON_ADDRESS
147 | LDR R2, [R0]
148 | ORRS R2, R1
149 | STR R2, [R0]
150 |
151 | LDR R0, =NRF_POWER_RAMONB_ADDRESS
152 | LDR R2, [R0]
153 | ORRS R2, R1
154 | STR R2, [R0]
155 |
156 | /* Loop to copy data from read only memory to RAM. The ranges
157 | * of copy from/to are specified by following symbols evaluated in
158 | * linker script.
159 | * __etext: End of code section, i.e., begin of data sections to copy from.
160 | * __data_start__/__data_end__: RAM address range that data should be
161 | * copied to. Both must be aligned to 4 bytes boundary. */
162 |
163 | ldr r1, =__etext
164 | ldr r2, =__data_start__
165 | ldr r3, =__data_end__
166 |
167 | subs r3, r2
168 | ble .LC0
169 |
170 | .LC1:
171 | subs r3, 4
172 | ldr r0, [r1,r3]
173 | str r0, [r2,r3]
174 | bgt .LC1
175 | .LC0:
176 |
177 | LDR R0, =SystemInit
178 | BLX R0
179 | LDR R0, =_start
180 | BX R0
181 |
182 | .pool
183 | .cantunwind
184 | .fnend
185 | .size Reset_Handler,.-Reset_Handler
186 |
187 | .section ".text"
188 |
189 |
190 | /* Dummy Exception Handlers (infinite loops which can be modified) */
191 |
192 | .weak NMI_Handler
193 | .type NMI_Handler, %function
194 | NMI_Handler:
195 | B .
196 | .size NMI_Handler, . - NMI_Handler
197 |
198 |
199 | .weak HardFault_Handler
200 | .type HardFault_Handler, %function
201 | HardFault_Handler:
202 | B .
203 | .size HardFault_Handler, . - HardFault_Handler
204 |
205 |
206 | .weak SVC_Handler
207 | .type SVC_Handler, %function
208 | SVC_Handler:
209 | B .
210 | .size SVC_Handler, . - SVC_Handler
211 |
212 |
213 | .weak PendSV_Handler
214 | .type PendSV_Handler, %function
215 | PendSV_Handler:
216 | B .
217 | .size PendSV_Handler, . - PendSV_Handler
218 |
219 |
220 | .weak SysTick_Handler
221 | .type SysTick_Handler, %function
222 | SysTick_Handler:
223 | B .
224 | .size SysTick_Handler, . - SysTick_Handler
225 |
226 |
227 | /* IRQ Handlers */
228 |
229 | .globl Default_Handler
230 | .type Default_Handler, %function
231 | Default_Handler:
232 | B .
233 | .size Default_Handler, . - Default_Handler
234 |
235 | .macro IRQ handler
236 | .weak \handler
237 | .set \handler, Default_Handler
238 | .endm
239 |
240 | IRQ POWER_CLOCK_IRQHandler
241 | IRQ RADIO_IRQHandler
242 | IRQ UART0_IRQHandler
243 | IRQ SPI0_TWI0_IRQHandler
244 | IRQ SPI1_TWI1_IRQHandler
245 | IRQ GPIOTE_IRQHandler
246 | IRQ ADC_IRQHandler
247 | IRQ TIMER0_IRQHandler
248 | IRQ TIMER1_IRQHandler
249 | IRQ TIMER2_IRQHandler
250 | IRQ RTC0_IRQHandler
251 | IRQ TEMP_IRQHandler
252 | IRQ RNG_IRQHandler
253 | IRQ ECB_IRQHandler
254 | IRQ CCM_AAR_IRQHandler
255 | IRQ WDT_IRQHandler
256 | IRQ RTC1_IRQHandler
257 | IRQ QDEC_IRQHandler
258 | IRQ LPCOMP_IRQHandler
259 | IRQ SWI0_IRQHandler
260 | IRQ SWI1_IRQHandler
261 | IRQ SWI2_IRQHandler
262 | IRQ SWI3_IRQHandler
263 | IRQ SWI4_IRQHandler
264 | IRQ SWI5_IRQHandler
265 |
266 | .end
267 |
--------------------------------------------------------------------------------
/android/Key20/app/src/main/java/de/frank_durr/key20/KeyExchangeFragment.java:
--------------------------------------------------------------------------------
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 | package de.frank_durr.key20;
20 |
21 | import android.app.Activity;
22 | import android.os.Bundle;
23 | import android.os.Handler;
24 | import android.os.Message;
25 | import android.support.design.widget.FloatingActionButton;
26 | import android.support.v4.app.Fragment;
27 | import android.text.Html;
28 | import android.view.LayoutInflater;
29 | import android.view.View;
30 | import android.view.ViewGroup;
31 | import android.widget.ArrayAdapter;
32 | import android.widget.Button;
33 | import android.widget.ProgressBar;
34 | import android.widget.Spinner;
35 | import android.widget.TextView;
36 | import android.widget.Toast;
37 |
38 | import java.lang.ref.WeakReference;
39 |
40 | /**
41 | * This fragment shows the UI for performing a key exchange with the remote lock control device.
42 | */
43 | public class KeyExchangeFragment extends Fragment {
44 |
45 | private Spinner spinnerKeyNo;
46 | private Button buttonConfirmKey;
47 | private TextView textViewChecksum;
48 | private TextView textViewInstructions;
49 | private FloatingActionButton floatingActionButton;
50 | private ProgressBar progressBar;
51 |
52 | private WeakReference activity;
53 |
54 | public MessageHandler msgHandler;
55 |
56 | /**
57 | * Handler for messages to the fragment.
58 | *
59 | * The handler runs in the UI thread.
60 | *
61 | * We make this class a static nested class, so a reference to the message handler (and
62 | * pending messages obtained from this handler) will not prevent the outer class from being
63 | * garbage-collected through a strong reference from a (non-static) inner to its outer class.
64 | * There is no point in keeping the fragment alive just to receive pending messages, which are
65 | * anyway not handled anymore by a "dead" fragment.
66 | */
67 | public static class MessageHandler extends Handler {
68 | public final static int DISPLAY_SECRET_CHECKSUM = 0;
69 | public final static int TASK_STARTED = 1;
70 | public final static int TASK_FINISHED = 2;
71 |
72 | private final WeakReference fragment;
73 |
74 | public MessageHandler(KeyExchangeFragment fragment) {
75 | this.fragment = new WeakReference(fragment);
76 | }
77 |
78 | @Override
79 | public void handleMessage(Message message) {
80 | // Get a strong reference to the fragment.
81 | KeyExchangeFragment f = fragment.get();
82 | if (f == null) {
83 | // The fragment has been garbage-collected.
84 | return;
85 | }
86 |
87 | switch (message.what) {
88 | case DISPLAY_SECRET_CHECKSUM :
89 | // Checksum is displayed as 16 hex digits with the lowest-order byte
90 | // at string index 0/1, i.e., checksum[0] is displayed leftmost.
91 | byte[] checksum = (byte[]) message.obj;
92 | String checksumStr = binarytoHexString(checksum);
93 | f.textViewChecksum.setText(checksumStr);
94 | break;
95 | case TASK_STARTED :
96 | // Delete old checksum, so it will not be confused with the new one.
97 | f.textViewChecksum.setText("");
98 | f.progressBar.setVisibility(View.VISIBLE);
99 | break;
100 | case TASK_FINISHED :
101 | f.progressBar.setVisibility(View.INVISIBLE);
102 | break;
103 | }
104 | }
105 | }
106 |
107 | static private String binarytoHexString(byte[] binary)
108 | {
109 | StringBuilder sb = new StringBuilder(binary.length*2);
110 |
111 | // Lowest order byte at index 0/1 of the string.
112 | for (int i = 0; i < binary.length; i++) {
113 | // High nibble first, i.e., to the left.
114 | // Note that bytes are signed in Java. However, "int x = abyte&0xff" will always
115 | // return an int value of x between 0 and 255.
116 | // "int v = binary[i]>>4" (without &0xff) does *not* work.
117 | int v = (binary[i]&0xff)>>4;
118 | char c;
119 | if (v < 10) {
120 | c = (char) ('0'+v);
121 | } else {
122 | c = (char) ('a'+v-10);
123 | }
124 | sb.append(c);
125 | // low nibble
126 | v = binary[i]&0x0f;
127 | if (v < 10) {
128 | c = (char) ('0'+v);
129 | } else {
130 | c = (char) ('a'+v-10);
131 | }
132 | sb.append(c);
133 | }
134 |
135 | return sb.toString();
136 | }
137 |
138 | /**
139 | * Use this factory method to create a new instance of
140 | * this fragment using the provided parameters.
141 | *
142 | * @return A new instance of fragment UnlockFragment.
143 | */
144 | public static KeyExchangeFragment newInstance() {
145 | KeyExchangeFragment fragment = new KeyExchangeFragment();
146 |
147 | Bundle args = new Bundle();
148 | fragment.setArguments(args);
149 |
150 | return fragment;
151 | }
152 |
153 | /**
154 | * An empty constructor is required.
155 | */
156 | public KeyExchangeFragment() {
157 | }
158 |
159 | @Override
160 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
161 | Bundle savedInstanceState) {
162 | // Inflate the layout for this fragment
163 | View v = inflater.inflate(R.layout.fragment_keyexchange, container, false);
164 |
165 | progressBar = (ProgressBar) v.findViewById(R.id.progressbar_keyexchange);
166 | progressBar.setVisibility(View.INVISIBLE);
167 |
168 | spinnerKeyNo = (Spinner) v.findViewById(R.id.spinner_keyno);
169 | ArrayAdapter adapter = ArrayAdapter.createFromResource(v.getContext(),
170 | R.array.spinner_keyno_choices, android.R.layout.simple_spinner_item);
171 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
172 | spinnerKeyNo.setAdapter(adapter);
173 |
174 | floatingActionButton = (FloatingActionButton) v.findViewById(R.id.fab_keyex);
175 | floatingActionButton.setOnClickListener(new View.OnClickListener() {
176 | @Override
177 | public void onClick(View v) {
178 | // Get a strong reference to the activity.
179 | MainActivity activity = KeyExchangeFragment.this.activity.get();
180 | if (activity == null) {
181 | // The activity has already been garbage collected.
182 | return;
183 | }
184 |
185 | Message msg;
186 | msg = activity.applicationEventHandler.obtainMessage(
187 | MainActivity.ApplicationEventHandler.START_KEYEXCHANGE);
188 | int selectedKeyNo = spinnerKeyNo.getSelectedItemPosition();
189 | if (selectedKeyNo == Spinner.INVALID_POSITION) {
190 | Toast.makeText(KeyExchangeFragment.this.getContext(),
191 | R.string.err_invalid_keyno, Toast.LENGTH_LONG).show();
192 | } else {
193 | msg.arg1 = selectedKeyNo;
194 | activity.applicationEventHandler.sendMessage(msg);
195 | }
196 | }
197 | });
198 |
199 | textViewChecksum = (TextView) v.findViewById(R.id.textview_checksum);
200 | textViewChecksum.setText("");
201 |
202 | buttonConfirmKey = (Button) v.findViewById(R.id.button_keyex_confirm);
203 | buttonConfirmKey.setOnClickListener(new View.OnClickListener() {
204 | @Override public void onClick(View v) {
205 | // Get a strong reference to the activity.
206 | MainActivity activity = KeyExchangeFragment.this.activity.get();
207 | if (activity == null) {
208 | // The activity has already been garbage collected.
209 | return;
210 | }
211 |
212 | Message msg;
213 | msg = activity.applicationEventHandler.obtainMessage(
214 | MainActivity.ApplicationEventHandler.USER_KEY_CONFIRMED);
215 | activity.applicationEventHandler.sendMessage(msg);
216 | }
217 | });
218 |
219 | textViewInstructions= (TextView) v.findViewById(R.id.textview_keyex_instructions);
220 | textViewInstructions.setText(Html.fromHtml(getString(R.string.keyex_instructions)));
221 |
222 | msgHandler = new MessageHandler(this);
223 |
224 | return v;
225 | }
226 |
227 | @Override
228 | public void onAttach(Activity activity) {
229 | super.onAttach(activity);
230 | this.activity = new WeakReference((MainActivity) activity);
231 | }
232 | }
233 |
--------------------------------------------------------------------------------
/LICENSE-HARDWARE:
--------------------------------------------------------------------------------
1 | CERN Open Hardware Licence v1.2
2 |
3 | Preamble
4 |
5 | Through this CERN Open Hardware Licence ("CERN OHL") version 1.2, CERN
6 | wishes to provide a tool to foster collaboration and sharing among
7 | hardware designers. The CERN OHL is copyright CERN. Anyone is welcome
8 | to use the CERN OHL, in unmodified form only, for the distribution of
9 | their own Open Hardware designs. Any other right is reserved. Release
10 | of hardware designs under the CERN OHL does not constitute an
11 | endorsement of the licensor or its designs nor does it imply any
12 | involvement by CERN in the development of such designs.
13 |
14 | 1. Definitions
15 |
16 | In this Licence, the following terms have the following meanings:
17 |
18 | “Licence” means this CERN OHL.
19 |
20 | “Documentation” means schematic diagrams, designs, circuit or circuit
21 | board layouts, mechanical drawings, flow charts and descriptive text,
22 | and other explanatory material that is explicitly stated as being made
23 | available under the conditions of this Licence. The Documentation may
24 | be in any medium, including but not limited to computer files and
25 | representations on paper, film, or any other media.
26 |
27 | “Documentation Location” means a location where the Licensor has
28 | placed Documentation, and which he believes will be publicly
29 | accessible for at least three years from the first communication to
30 | the public or distribution of Documentation.
31 |
32 | “Product” means either an entire, or any part of a, device built using
33 | the Documentation or the modified Documentation.
34 |
35 | “Licensee” means any natural or legal person exercising rights under
36 | this Licence.
37 |
38 | “Licensor” means any natural or legal person that creates or modifies
39 | Documentation and subsequently communicates to the public and/ or
40 | distributes the resulting Documentation under the terms and conditions
41 | of this Licence.
42 |
43 | A Licensee may at the same time be a Licensor, and vice versa.
44 |
45 | Use of the masculine gender includes the feminine and neuter genders
46 | and is employed solely to facilitate reading.
47 |
48 | 2. Applicability
49 |
50 | 2.1. This Licence governs the use, copying, modification,
51 | communication to the public and distribution of the Documentation, and
52 | the manufacture and distribution of Products. By exercising any right
53 | granted under this Licence, the Licensee irrevocably accepts these
54 | terms and conditions.
55 |
56 | 2.2. This Licence is granted by the Licensor directly to the Licensee,
57 | and shall apply worldwide and without limitation in time. The Licensee
58 | may assign his licence rights or grant sub-licences.
59 |
60 | 2.3. This Licence does not extend to software, firmware, or code
61 | loaded into programmable devices which may be used in conjunction with
62 | the Documentation, the modified Documentation or with Products, unless
63 | such software, firmware, or code is explicitly expressed to be subject
64 | to this Licence. The use of such software, firmware, or code is
65 | otherwise subject to the applicable licence terms and conditions.
66 |
67 | 3. Copying, modification, communication to the public and distribution
68 | of the Documentation
69 |
70 | 3.1. The Licensee shall keep intact all copyright and trademarks
71 | notices, all notices referring to Documentation Location, and all
72 | notices that refer to this Licence and to the disclaimer of warranties
73 | that are included in the Documentation. He shall include a copy
74 | thereof in every copy of the Documentation or, as the case may be,
75 | modified Documentation, that he communicates to the public or
76 | distributes.
77 |
78 | 3.2. The Licensee may copy, communicate to the public and distribute
79 | verbatim copies of the Documentation, in any medium, subject to the
80 | requirements specified in section 3.1.
81 |
82 | 3.3. The Licensee may modify the Documentation or any portion thereof
83 | provided that upon modification of the Documentation, the Licensee
84 | shall make the modified Documentation available from a Documentation
85 | Location such that it can be easily located by an original Licensor
86 | once the Licensee communicates to the public or distributes the
87 | modified Documentation under section 3.4, and, where required by
88 | section 4.1, by a recipient of a Product. However, the Licensor shall
89 | not assert his rights under the foregoing proviso unless or until a
90 | Product is distributed.
91 |
92 | 3.4. The Licensee may communicate to the public and distribute the
93 | modified Documentation (thereby in addition to being a Licensee also
94 | becoming a Licensor), always provided that he shall:
95 |
96 | a) comply with section 3.1;
97 |
98 | b) cause the modified Documentation to carry prominent notices stating
99 | that the Licensee has modified the Documentation, with the date and
100 | description of the modifications;
101 |
102 | c) cause the modified Documentation to carry a new Documentation
103 | Location notice if the original Documentation provided for one;
104 |
105 | d) make available the modified Documentation at the same level of
106 | abstraction as that of the Documentation, in the preferred format for
107 | making modifications to it (e.g. the native format of the CAD tool as
108 | applicable), and in the event that format is proprietary, in a format
109 | viewable with a tool licensed under an OSI-approved license if the
110 | proprietary tool can create it; and
111 |
112 | e) license the modified Documentation under the terms and conditions
113 | of this Licence or, where applicable, a later version of this Licence
114 | as may be issued by CERN.
115 |
116 | 3.5. The Licence includes a non-exclusive licence to those patents or
117 | registered designs that are held by, under the control of, or
118 | sub-licensable by the Licensor, to the extent necessary to make use of
119 | the rights granted under this Licence. The scope of this section 3.5
120 | shall be strictly limited to the parts of the Documentation or
121 | modified Documentation created by the Licensor.
122 |
123 | 4. Manufacture and distribution of Products
124 |
125 | 4.1. The Licensee may manufacture or distribute Products always
126 | provided that, where such manufacture or distribution requires a
127 | licence under this Licence the Licensee provides to each recipient of
128 | such Products an easy means of accessing a copy of the Documentation
129 | or modified Documentation, as applicable, as set out in section 3.
130 |
131 | 4.2. The Licensee is invited to inform any Licensor who has indicated
132 | his wish to receive this information about the type, quantity and
133 | dates of production of Products the Licensee has (had) manufactured
134 |
135 | 5. Warranty and liability
136 |
137 | 5.1. DISCLAIMER – The Documentation and any modified Documentation are
138 | provided "as is" and any express or implied warranties, including, but
139 | not limited to, implied warranties of merchantability, of satisfactory
140 | quality, non-infringement of third party rights, and fitness for a
141 | particular purpose or use are disclaimed in respect of the
142 | Documentation, the modified Documentation or any Product. The Licensor
143 | makes no representation that the Documentation, modified
144 | Documentation, or any Product, does or will not infringe any patent,
145 | copyright, trade secret or other proprietary right. The entire risk as
146 | to the use, quality, and performance of a Product shall be with the
147 | Licensee and not the Licensor. This disclaimer of warranty is an
148 | essential part of this Licence and a condition for the grant of any
149 | rights granted under this Licence. The Licensee warrants that it does
150 | not act in a consumer capacity.
151 |
152 | 5.2. LIMITATION OF LIABILITY – The Licensor shall have no liability
153 | for direct, indirect, special, incidental, consequential, exemplary,
154 | punitive or other damages of any character including, without
155 | limitation, procurement of substitute goods or services, loss of use,
156 | data or profits, or business interruption, however caused and on any
157 | theory of contract, warranty, tort (including negligence), product
158 | liability or otherwise, arising in any way in relation to the
159 | Documentation, modified Documentation and/or the use, manufacture or
160 | distribution of a Product, even if advised of the possibility of such
161 | damages, and the Licensee shall hold the Licensor(s) free and harmless
162 | from any liability, costs, damages, fees and expenses, including
163 | claims by third parties, in relation to such use.
164 |
165 | 6. General
166 |
167 | 6.1. Except for the rights explicitly granted hereunder, this Licence
168 | does not imply or represent any transfer or assignment of intellectual
169 | property rights to the Licensee.
170 |
171 | 6.2. The Licensee shall not use or make reference to any of the names
172 | (including acronyms and abbreviations), images, or logos under which
173 | the Licensor is known, save in so far as required to comply with
174 | section 3. Any such permitted use or reference shall be factual and
175 | shall in no event suggest any kind of endorsement by the Licensor or
176 | its personnel of the modified Documentation or any Product, or any
177 | kind of implication by the Licensor or its personnel in the
178 | preparation of the modified Documentation or Product.
179 |
180 | 6.3. CERN may publish updated versions of this Licence which retain
181 | the same general provisions as this version, but differ in detail so
182 | far this is required and reasonable. New versions will be published
183 | with a unique version number.
184 |
185 | 6.4. This Licence shall terminate with immediate effect, upon written
186 | notice and without involvement of a court if the Licensee fails to
187 | comply with any of its terms and conditions, or if the Licensee
188 | initiates legal action against Licensor in relation to this
189 | Licence. Section 5 shall continue to apply.
190 |
--------------------------------------------------------------------------------
/avrnacl/avrnacl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: avrnacl.h
3 | * Author: Michael Hutter, Peter Schwabe
4 | * Version: Tue Aug 12 08:23:16 2014 +0200
5 | * Public Domain
6 | */
7 |
8 | #ifndef AVRNACL_H
9 | #define AVRNACL_H
10 | #define AVRNACL_VERSION "2014-07-XXX"
11 |
12 | // Change compared to original avrnacl: using standard int types.
13 | #include
14 |
15 | typedef int8_t crypto_int8;
16 | typedef uint8_t crypto_uint8;
17 | typedef int16_t crypto_int16;
18 | typedef uint16_t crypto_uint16;
19 | typedef int32_t crypto_int32;
20 | typedef uint32_t crypto_uint32;
21 | typedef int64_t crypto_int64;
22 | typedef uint64_t crypto_uint64;
23 |
24 | #define crypto_auth_PRIMITIVE "hmacsha512256"
25 | #define crypto_auth crypto_auth_hmacsha512256
26 | #define crypto_auth_verify crypto_auth_hmacsha512256_verify
27 | #define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES
28 | #define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES
29 | #define crypto_auth_hmacsha512256_BYTES 32
30 | #define crypto_auth_hmacsha512256_KEYBYTES 32
31 | extern int crypto_auth_hmacsha512256(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *);
32 | extern int crypto_auth_hmacsha512256_verify(const unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *);
33 |
34 | // Change compared to original avrnacl: removed all unused functions and
35 | // definitions.
36 | /*
37 | #define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"
38 | #define crypto_box crypto_box_curve25519xsalsa20poly1305
39 | #define crypto_box_open crypto_box_curve25519xsalsa20poly1305_open
40 | #define crypto_box_keypair crypto_box_curve25519xsalsa20poly1305_keypair
41 | #define crypto_box_beforenm crypto_box_curve25519xsalsa20poly1305_beforenm
42 | #define crypto_box_afternm crypto_box_curve25519xsalsa20poly1305_afternm
43 | #define crypto_box_open_afternm crypto_box_curve25519xsalsa20poly1305_open_afternm
44 | #define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
45 | #define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
46 | #define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
47 | #define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
48 | #define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
49 | #define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
50 | #define crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES 32
51 | #define crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES 32
52 | #define crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES 32
53 | #define crypto_box_curve25519xsalsa20poly1305_NONCEBYTES 24
54 | #define crypto_box_curve25519xsalsa20poly1305_ZEROBYTES 32
55 | #define crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES 16
56 | extern int crypto_box_curve25519xsalsa20poly1305(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *,const unsigned char *);
57 | extern int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *,const unsigned char *);
58 | extern int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *,unsigned char *);
59 | extern int crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *,const unsigned char *,const unsigned char *);
60 | extern int crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
61 | extern int crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
62 |
63 | #define crypto_core_PRIMITIVE "salsa20"
64 | #define crypto_core crypto_core_salsa20
65 | #define crypto_core_OUTPUTBYTES crypto_core_salsa20_OUTPUTBYTES
66 | #define crypto_core_INPUTBYTES crypto_core_salsa20_INPUTBYTES
67 | #define crypto_core_KEYBYTES crypto_core_salsa20_KEYBYTES
68 | #define crypto_core_CONSTBYTES crypto_core_salsa20_CONSTBYTES
69 | #define crypto_core_salsa20_OUTPUTBYTES 64
70 | #define crypto_core_salsa20_INPUTBYTES 16
71 | #define crypto_core_salsa20_KEYBYTES 32
72 | #define crypto_core_salsa20_CONSTBYTES 16
73 | extern int crypto_core_salsa20(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
74 |
75 | #define crypto_core_hsalsa20_OUTPUTBYTES 32
76 | #define crypto_core_hsalsa20_INPUTBYTES 16
77 | #define crypto_core_hsalsa20_KEYBYTES 32
78 | #define crypto_core_hsalsa20_CONSTBYTES 16
79 | extern int crypto_core_hsalsa20(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
80 | */
81 |
82 | #define crypto_hashblocks_PRIMITIVE "sha512"
83 | #define crypto_hashblocks crypto_hashblocks_sha512
84 | #define crypto_hashblocks_STATEBYTES crypto_hashblocks_sha512_STATEBYTES
85 | #define crypto_hashblocks_BLOCKBYTES crypto_hashblocks_sha512_BLOCKBYTES
86 | #define crypto_hashblocks_sha512_STATEBYTES 64
87 | #define crypto_hashblocks_sha512_BLOCKBYTES 128
88 | extern int crypto_hashblocks_sha512(unsigned char *,const unsigned char *,crypto_uint16);
89 |
90 | #define crypto_hash_PRIMITIVE "sha512"
91 | #define crypto_hash crypto_hash_sha512
92 | #define crypto_hash_BYTES crypto_hash_sha512_BYTES
93 | #define crypto_hash_sha512_BYTES 64
94 | extern int crypto_hash_sha512(unsigned char *,const unsigned char *,crypto_uint16);
95 |
96 | /*
97 | #define crypto_onetimeauth_PRIMITIVE "poly1305"
98 | #define crypto_onetimeauth crypto_onetimeauth_poly1305
99 | #define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_verify
100 | #define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES
101 | #define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES
102 | #define crypto_onetimeauth_poly1305_BYTES 16
103 | #define crypto_onetimeauth_poly1305_KEYBYTES 32
104 | extern int crypto_onetimeauth_poly1305(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *);
105 | extern int crypto_onetimeauth_poly1305_verify(const unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *);
106 |
107 | #define crypto_scalarmult_PRIMITIVE "curve25519"
108 | #define crypto_scalarmult crypto_scalarmult_curve25519
109 | #define crypto_scalarmult_base crypto_scalarmult_curve25519_base
110 | #define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES
111 | #define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES
112 | #define crypto_scalarmult_curve25519_BYTES 32
113 | #define crypto_scalarmult_curve25519_SCALARBYTES 32
114 | extern int crypto_scalarmult_curve25519(unsigned char *,const unsigned char *,const unsigned char *);
115 | extern int crypto_scalarmult_curve25519_base(unsigned char *,const unsigned char *);
116 |
117 | #define crypto_dh_PRIMITIVE "curve25519"
118 | #define crypto_dh crypto_dh_curve25519
119 | #define crypto_dh_keypair crypto_dh_curve25519_keypair
120 | #define crypto_dh_BYTES crypto_dh_curve25519_BYTES
121 | #define crypto_dh_SECRETKEYBYTES crypto_dh_curve25519_SECRETKEYBYTES
122 | #define crypto_dh_PUBLICKEYBYTES crypto_dh_curve25519_PUBLICKEYBYTES
123 | #define crypto_dh_BYTES crypto_dh_curve25519_BYTES
124 | #define crypto_dh_curve25519_SECRETKEYBYTES 32
125 | #define crypto_dh_curve25519_PUBLICKEYBYTES 32
126 | #define crypto_dh_curve25519_BYTES 32
127 | extern int crypto_dh_curve25519(unsigned char *,const unsigned char *,const unsigned char *);
128 | extern int crypto_dh_curve25519_keypair(unsigned char *,unsigned char *);
129 |
130 | #define crypto_secretbox_PRIMITIVE "xsalsa20poly1305"
131 | #define crypto_secretbox crypto_secretbox_xsalsa20poly1305
132 | #define crypto_secretbox_open crypto_secretbox_xsalsa20poly1305_open
133 | #define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES
134 | #define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES
135 | #define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES
136 | #define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES
137 | #define crypto_secretbox_xsalsa20poly1305_KEYBYTES 32
138 | #define crypto_secretbox_xsalsa20poly1305_NONCEBYTES 24
139 | #define crypto_secretbox_xsalsa20poly1305_ZEROBYTES 32
140 | #define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES 16
141 | extern int crypto_secretbox_xsalsa20poly1305(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
142 | extern int crypto_secretbox_xsalsa20poly1305_open(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
143 |
144 | #define crypto_sign_PRIMITIVE "ed25519"
145 | #define crypto_sign crypto_sign_ed25519
146 | #define crypto_sign_open crypto_sign_ed25519_open
147 | #define crypto_sign_keypair crypto_sign_ed25519_keypair
148 | #define crypto_sign_BYTES crypto_sign_ed25519_BYTES
149 | #define crypto_sign_PUBLICKEYBYTES crypto_sign_ed25519_PUBLICKEYBYTES
150 | #define crypto_sign_SECRETKEYBYTES crypto_sign_ed25519_SECRETKEYBYTES
151 | #define crypto_sign_ed25519_BYTES 64
152 | #define crypto_sign_ed25519_PUBLICKEYBYTES 32
153 | #define crypto_sign_ed25519_SECRETKEYBYTES 64
154 | extern int crypto_sign_ed25519(unsigned char *,crypto_uint16 *,const unsigned char *,crypto_uint16,const unsigned char *);
155 | extern int crypto_sign_ed25519_open(unsigned char *,crypto_uint16 *,const unsigned char *,crypto_uint16,const unsigned char *);
156 | extern int crypto_sign_ed25519_keypair(unsigned char *,unsigned char *);
157 |
158 | #define crypto_stream_PRIMITIVE "xsalsa20"
159 | #define crypto_stream crypto_stream_xsalsa20
160 | #define crypto_stream_xor crypto_stream_xsalsa20_xor
161 | #define crypto_stream_KEYBYTES crypto_stream_xsalsa20_KEYBYTES
162 | #define crypto_stream_NONCEBYTES crypto_stream_xsalsa20_NONCEBYTES
163 | #define crypto_stream_xsalsa20_KEYBYTES 32
164 | #define crypto_stream_xsalsa20_NONCEBYTES 24
165 | extern int crypto_stream_xsalsa20(unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
166 | extern int crypto_stream_xsalsa20_xor(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
167 |
168 | #define crypto_stream_salsa20_KEYBYTES 32
169 | #define crypto_stream_salsa20_NONCEBYTES 8
170 | extern int crypto_stream_salsa20(unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
171 | extern int crypto_stream_salsa20_xor(unsigned char *,const unsigned char *,crypto_uint16,const unsigned char *,const unsigned char *);
172 |
173 | #define crypto_verify_PRIMITIVE "16"
174 | #define crypto_verify crypto_verify_16
175 | #define crypto_verify_BYTES crypto_verify_16_BYTES
176 | #define crypto_verify_16_BYTES 16
177 | extern int crypto_verify_16(const unsigned char *,const unsigned char *);
178 |
179 | #define crypto_verify_32_BYTES 32
180 | extern int crypto_verify_32(const unsigned char *,const unsigned char *);
181 | */
182 |
183 | #endif
184 |
--------------------------------------------------------------------------------
/hd44780nrf51/hd44780nrf51.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Frank Duerr
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "hd44780nrf51.h"
18 | #include
19 | #include
20 |
21 | // Waiting time for fast instructions [us]. Must be longer than 40 us.
22 | #define SHORT_WAIT 50
23 | // Waiting time for slow instructions [ms]. Must be longer than 1.52 ms.
24 | #define LONG_WAIT 2
25 |
26 | // The following definitions should make it easy to port the code to other
27 | // platforms than nRF51.
28 | #define PIN_CFG_OUTPOUT(X) nrf_gpio_cfg_output(X)
29 | #define PIN_CLR(X) nrf_gpio_pin_clear(X)
30 | #define PIN_SET(X) nrf_gpio_pin_set(X)
31 | #define DELAY_MS(X) nrf_delay_ms(X)
32 | #define DELAY_US(X) nrf_delay_us(X)
33 |
34 | /**
35 | * Wait for fast instructions requiring 37 us to 40 us waiting time.
36 | */
37 | static void short_instr_wait()
38 | {
39 | DELAY_US(SHORT_WAIT);
40 | }
41 |
42 | /**
43 | * Wait for slow instructions requiring 1.52 ms waiting time.
44 | */
45 | static void long_instr_wait()
46 | {
47 | DELAY_MS(LONG_WAIT);
48 | }
49 |
50 | /**
51 | * Send enable pulse.
52 | *
53 | * The enable pin is set high for 1 us, then low for 1 us.
54 | * According to the data sheet, the pulse width must be at least 450 ns,
55 | * and the maximum cycle time at least 1 us.
56 | *
57 | * @param lcd definition of the LCD display to be used.
58 | */
59 | static void enable(const struct hd44780 *lcd)
60 | {
61 | // Send pulse of 1 us width.
62 | PIN_SET(lcd->pin_e);
63 | DELAY_US(1);
64 | // Clear pin for 1 us.
65 | PIN_CLR(lcd->pin_e);
66 | DELAY_US(1);
67 | }
68 |
69 | /**
70 | * Set nibble of 4 bits on data pins. The four bits are the 4 LSBs of
71 | * parameter "bits".
72 | *
73 | * @param lcd definition of the LCD display to be used.
74 | * @param bits the 4 LSBs of this byte will be used to set the nibble.
75 | */
76 | static void set_nibble(const struct hd44780 *lcd, uint8_t bits)
77 | {
78 | if (bits&0x1)
79 | PIN_SET(lcd->pin_db4);
80 | else
81 | PIN_CLR(lcd->pin_db4);
82 |
83 | if (bits&0x2)
84 | PIN_SET(lcd->pin_db5);
85 | else
86 | PIN_CLR(lcd->pin_db5);
87 |
88 | if (bits&0x4)
89 | PIN_SET(lcd->pin_db6);
90 | else
91 | PIN_CLR(lcd->pin_db6);
92 |
93 | if (bits&0x8)
94 | PIN_SET(lcd->pin_db7);
95 | else
96 | PIN_CLR(lcd->pin_db7);
97 | }
98 |
99 | /**
100 | * Send one byte output as two nibbles in 4 bit mode (first high nibble,
101 | * then low nibble).
102 | *
103 | * @param lcd definition of the LCD display to be used.
104 | * @param data the byte to be sent.
105 | */
106 | static void send_byte(const struct hd44780 *lcd, uint8_t data)
107 | {
108 | uint8_t nibble = (data >> 4);
109 | set_nibble(lcd, nibble);
110 | enable(lcd);
111 |
112 | nibble = (data & 0x0f);
113 | set_nibble(lcd, nibble);
114 | enable(lcd);
115 | }
116 |
117 | /**
118 | * Initialize pins.
119 | *
120 | * All pins are set as outputs with low level.
121 | *
122 | * @param lcd definition of the LCD display to be used.
123 | */
124 | static void init_pins(const struct hd44780 *lcd)
125 | {
126 | // All pins are outputs.
127 | PIN_CFG_OUTPOUT(lcd->pin_rs);
128 | PIN_CFG_OUTPOUT(lcd->pin_e);
129 | PIN_CFG_OUTPOUT(lcd->pin_db4);
130 | PIN_CFG_OUTPOUT(lcd->pin_db5);
131 | PIN_CFG_OUTPOUT(lcd->pin_db6);
132 | PIN_CFG_OUTPOUT(lcd->pin_db7);
133 |
134 | // Set all pins low.
135 | PIN_CLR(lcd->pin_rs);
136 | PIN_CLR(lcd->pin_e);
137 | PIN_CLR(lcd->pin_db4);
138 | PIN_CLR(lcd->pin_db5);
139 | PIN_CLR(lcd->pin_db6);
140 | PIN_CLR(lcd->pin_db7);
141 | }
142 |
143 | /**
144 | * Send function set command.
145 | *
146 | * This command sets two pieces of information:
147 | *
148 | * The number of lines (1 or 2). This information is taken from parameter
149 | * lcd.
150 | *
151 | * The character font (5x8 dots or 5x10 dots). Since 5x10 dot fonts are
152 | * seldomly implemented by displays, we always use the 5x8 dots font.
153 | *
154 | * @param lcd definition of the LCD display to be used.
155 | */
156 | static void cmd_function_set(const struct hd44780 *lcd)
157 | {
158 | PIN_CLR(lcd->pin_rs);
159 |
160 | // Byte pattern: 0 0 1 DL N F * *
161 | // DL = 0: 4 bits data length; DL = 1: 8 bit data length
162 | // N = 0: 1 line; N = 1: 2 lines
163 | // F = 0: 5x8 dot font; F = 1: 5 x 10 font (seldomly implemented)
164 | uint8_t data = 0x20;
165 | data |= (lcd->rows == 1 ? 0x00 : 0x08);
166 | send_byte(lcd, data);
167 |
168 | short_instr_wait();
169 | }
170 |
171 | /**
172 | * Send display on/off command.
173 | *
174 | * @param lcd definition of the LCD display to be used.
175 | * @param display_on if true, turn on the display; otherwise turn display off.
176 | * @param cursor_on if true, show cursors; otherwise turn cursor off.
177 | * @param cursor_blinking if true, let cursor bling; otherwise don't blink.
178 | */
179 | static void cmd_display_on_off(const struct hd44780 *lcd, bool display_on,
180 | bool cursor_on, bool cursor_blinking)
181 | {
182 | PIN_CLR(lcd->pin_rs);
183 |
184 | // Byte pattern: 0 0 0 0 1 D C B
185 | // D: 0 = display off; 1 = display on
186 | // C: 0 = cursor off; 1 = cursor on
187 | // B: 0 = cursor not blinking; 1 = cursor blinking
188 | uint8_t data = 0x08;
189 | if (display_on)
190 | data |= 0x04;
191 | if (cursor_on)
192 | data |= 0x02;
193 | if (cursor_blinking)
194 | data |= 0x01;
195 | send_byte(lcd, data);
196 |
197 | short_instr_wait();
198 | }
199 |
200 | /**
201 | * Send clear display command.
202 | *
203 | * @param lcd definition of the LCD display to be used.
204 | */
205 | static void cmd_clear_display(const struct hd44780 *lcd)
206 | {
207 | PIN_CLR(lcd->pin_rs);
208 |
209 | // Byte pattern: 0 0 0 0 0 0 0 1
210 | uint8_t data = 0x01;
211 | send_byte(lcd, data);
212 |
213 | long_instr_wait();
214 | }
215 |
216 | /**
217 | * Set the DDRAM address for writing the next character.
218 | *
219 | * @param lcd definition of the LCD display to be used.
220 | * @param addr DDRAM address.
221 | */
222 | static void cmd_set_ddram_addr(const struct hd44780 *lcd, uint8_t addr)
223 | {
224 | PIN_CLR(lcd->pin_rs);
225 |
226 | uint8_t data = 0x80;
227 | data |= (addr & 0x7f);
228 | send_byte(lcd, data);
229 |
230 | short_instr_wait();
231 | }
232 |
233 | /**
234 | * Send set entry mode command.
235 | *
236 | * @param lcd definition of the LCD display to be used.
237 | * @param incded if true, increase DDRAM address after writing a character,
238 | * else decrease DDRAM address.
239 | * @param shift if true, shift entire display to left (incdec == false) or
240 | * right (incdec = true); otherwise do not shift display.
241 | */
242 | static void cmd_set_entry_mode(const struct hd44780 *lcd, bool incdec,
243 | bool shift)
244 | {
245 | PIN_CLR(lcd->pin_rs);
246 |
247 | // Byte pattern: 0 0 0 0 0 1 ID S
248 | // ID: increase (1) or decrease (0) DDRAM position after writing character.
249 | // S: shift entire display (1); do not shift display (0)
250 | uint8_t data = 0x04;
251 | if (incdec)
252 | data |= 0x02;
253 | if (shift)
254 | data |= 0x01;
255 | send_byte(lcd, data);
256 |
257 | short_instr_wait();
258 | }
259 |
260 | /**
261 | * Go through initialization sequence as described in HD44780 data sheet.
262 | *
263 | * After this sequence, the display is off and the cursor is off. The entry
264 | * mode is set to. DDRAM address increase after character write; no display
265 | * shift.
266 | *
267 | * @param lcd definition of the LCD display to be used.
268 | */
269 | static void init_sequence(const struct hd44780 *lcd)
270 | {
271 | // According to HD44780 data sheet, need to wait 40 ms
272 | // after voltage rises to 2.7 V. We give some safety margin since
273 | // we do not know exactly whether right at this point we have
274 | // already reached 2.7 V (brown-out detection of the nRF51 engages at
275 | // 1.7 V).
276 | DELAY_MS(100);
277 |
278 | PIN_CLR(lcd->pin_rs);
279 |
280 | set_nibble(lcd, 0x03);
281 | enable(lcd);
282 | // Need to wait more than 4.1 ms.
283 | DELAY_MS(9);
284 |
285 | set_nibble(lcd, 0x03);
286 | enable(lcd);
287 | // Need to wait more than 100 us.
288 | DELAY_US(200);
289 |
290 | set_nibble(lcd, 0x03);
291 | enable(lcd);
292 | short_instr_wait();
293 |
294 | set_nibble(lcd, 0x02);
295 | enable(lcd);
296 | short_instr_wait();
297 |
298 | // Set number of rows, font, and 4-bit mode.
299 | cmd_function_set(lcd);
300 |
301 | // Turn display off, cursor off, no blinking cursor.
302 | cmd_display_on_off(lcd, false, false, false);
303 |
304 | // Clear the display
305 | cmd_clear_display(lcd);
306 |
307 | // Set the entry mode: DDRAM address increase after writing,
308 | // no display shifting.
309 | cmd_set_entry_mode(lcd, true, false);
310 | }
311 |
312 | void hd44780_init(const struct hd44780 *lcd)
313 | {
314 | init_pins(lcd);
315 |
316 | init_sequence(lcd);
317 | }
318 |
319 | void hd44780_display_on_off(const struct hd44780 *lcd, bool display_on,
320 | bool cursor_on, bool cursor_blinking)
321 | {
322 | cmd_display_on_off(lcd, display_on, cursor_on, cursor_blinking);
323 | }
324 |
325 | void hd44780_print_line(const struct hd44780 *lcd, const char *text,
326 | unsigned int length, unsigned int line)
327 | {
328 | if (line == 0)
329 | cmd_set_ddram_addr(lcd, 0);
330 | else
331 | cmd_set_ddram_addr(lcd, HD44780_2nd_LINE_OFFSET);
332 |
333 | PIN_SET(lcd->pin_rs);
334 | for (unsigned int i = 0; i < length; i++) {
335 | uint8_t character = text[i];
336 | send_byte(lcd, character);
337 | short_instr_wait();
338 | // After the write operation, the DDRAM address is automatically
339 | // incremented by 1.
340 | }
341 | }
342 |
343 | void hd44780_clear_display(const struct hd44780 *lcd)
344 | {
345 | cmd_clear_display(lcd);
346 | }
347 |
348 | void hd44780_clear_line(const struct hd44780 *lcd, unsigned int line)
349 | {
350 | if (line == 0)
351 | cmd_set_ddram_addr(lcd, 0);
352 | else
353 | cmd_set_ddram_addr(lcd, HD44780_2nd_LINE_OFFSET);
354 |
355 | PIN_SET(lcd->pin_rs);
356 | for (unsigned int i = 0; i < lcd->columns; i++) {
357 | uint8_t character = ' ';
358 | send_byte(lcd, character);
359 | short_instr_wait();
360 | // After the write operation, the DDRAM address is automatically
361 | // incremented by 1.
362 | }
363 | }
364 |
--------------------------------------------------------------------------------
/nrf51/nrf_drv_config.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
2 | *
3 | * The information contained herein is property of Nordic Semiconductor ASA.
4 | * Terms and conditions of usage are described in detail in NORDIC
5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
6 | *
7 | * Licensees are granted free, non-transferable use of the information. NO
8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9 | * the file.
10 | *
11 | */
12 |
13 | #ifndef NRF_DRV_CONFIG_H
14 | #define NRF_DRV_CONFIG_H
15 |
16 | /* CLOCK */
17 | #define CLOCK_CONFIG_XTAL_FREQ NRF_CLOCK_XTALFREQ_Default
18 | #define CLOCK_CONFIG_LF_SRC NRF_CLOCK_LF_SRC_Xtal
19 | #define CLOCK_CONFIG_LF_RC_CAL_INTERVAL RC_2000MS_CALIBRATION_INTERVAL
20 | #define CLOCK_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
21 |
22 | /* GPIOTE */
23 | #define GPIOTE_ENABLED 1
24 |
25 | #if (GPIOTE_ENABLED == 1)
26 | #define GPIOTE_CONFIG_USE_SWI_EGU false
27 | #define GPIOTE_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
28 | #define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 4
29 | #endif
30 |
31 | /* TIMER */
32 | #define TIMER0_ENABLED 0
33 |
34 | #if (TIMER0_ENABLED == 1)
35 | #define TIMER0_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
36 | #define TIMER0_CONFIG_MODE TIMER_MODE_MODE_Timer
37 | #define TIMER0_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_32Bit
38 | #define TIMER0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
39 |
40 | #define TIMER0_INSTANCE_INDEX 0
41 | #endif
42 |
43 | #define TIMER1_ENABLED 0
44 |
45 | #if (TIMER1_ENABLED == 1)
46 | #define TIMER1_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
47 | #define TIMER1_CONFIG_MODE TIMER_MODE_MODE_Timer
48 | #define TIMER1_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
49 | #define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
50 |
51 | #define TIMER1_INSTANCE_INDEX (TIMER0_ENABLED)
52 | #endif
53 |
54 | #define TIMER2_ENABLED 0
55 |
56 | #if (TIMER2_ENABLED == 1)
57 | #define TIMER2_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
58 | #define TIMER2_CONFIG_MODE TIMER_MODE_MODE_Timer
59 | #define TIMER2_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
60 | #define TIMER2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
61 |
62 | #define TIMER2_INSTANCE_INDEX (TIMER1_ENABLED+TIMER0_ENABLED)
63 | #endif
64 |
65 | #define TIMER3_ENABLED 0
66 |
67 | #if (TIMER3_ENABLED == 1)
68 | #define TIMER3_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
69 | #define TIMER3_CONFIG_MODE TIMER_MODE_MODE_Timer
70 | #define TIMER3_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
71 | #define TIMER3_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
72 |
73 | #define TIMER3_INSTANCE_INDEX (TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
74 | #endif
75 |
76 | #define TIMER4_ENABLED 0
77 |
78 | #if (TIMER4_ENABLED == 1)
79 | #define TIMER4_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
80 | #define TIMER4_CONFIG_MODE TIMER_MODE_MODE_Timer
81 | #define TIMER4_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
82 | #define TIMER4_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
83 |
84 | #define TIMER4_INSTANCE_INDEX (TIMER3_ENABLED+TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
85 | #endif
86 |
87 |
88 | #define TIMER_COUNT (TIMER0_ENABLED + TIMER1_ENABLED + TIMER2_ENABLED + TIMER3_ENABLED + TIMER4_ENABLED)
89 |
90 | /* RTC */
91 | #define RTC0_ENABLED 0
92 |
93 | #if (RTC0_ENABLED == 1)
94 | #define RTC0_CONFIG_FREQUENCY 32678
95 | #define RTC0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
96 | #define RTC0_CONFIG_RELIABLE false
97 |
98 | #define RTC0_INSTANCE_INDEX 0
99 | #endif
100 |
101 | #define RTC1_ENABLED 0
102 |
103 | #if (RTC1_ENABLED == 1)
104 | #define RTC1_CONFIG_FREQUENCY 32768
105 | #define RTC1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
106 | #define RTC1_CONFIG_RELIABLE false
107 |
108 | #define RTC1_INSTANCE_INDEX (RTC0_ENABLED)
109 | #endif
110 |
111 | #define RTC_COUNT (RTC0_ENABLED+RTC1_ENABLED)
112 |
113 | #define NRF_MAXIMUM_LATENCY_US 2000
114 |
115 | /* RNG */
116 | #define RNG_ENABLED 1
117 |
118 | #if (RNG_ENABLED == 1)
119 | #define RNG_CONFIG_ERROR_CORRECTION true
120 | #define RNG_CONFIG_POOL_SIZE 8
121 | #define RNG_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
122 | #endif
123 |
124 | /* SPI */
125 | #define SPI0_ENABLED 0
126 |
127 | #if (SPI0_ENABLED == 1)
128 | #define SPI0_USE_EASY_DMA 0
129 |
130 | #define SPI0_CONFIG_SCK_PIN 2
131 | #define SPI0_CONFIG_MOSI_PIN 3
132 | #define SPI0_CONFIG_MISO_PIN 4
133 | #define SPI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
134 |
135 | #define SPI0_INSTANCE_INDEX 0
136 | #endif
137 |
138 | #define SPI1_ENABLED 0
139 |
140 | #if (SPI1_ENABLED == 1)
141 | #define SPI1_USE_EASY_DMA 0
142 |
143 | #define SPI1_CONFIG_SCK_PIN 2
144 | #define SPI1_CONFIG_MOSI_PIN 3
145 | #define SPI1_CONFIG_MISO_PIN 4
146 | #define SPI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
147 |
148 | #define SPI1_INSTANCE_INDEX (SPI0_ENABLED)
149 | #endif
150 |
151 | #define SPI2_ENABLED 0
152 |
153 | #if (SPI2_ENABLED == 1)
154 | #define SPI2_USE_EASY_DMA 0
155 |
156 | #define SPI2_CONFIG_SCK_PIN 2
157 | #define SPI2_CONFIG_MOSI_PIN 3
158 | #define SPI2_CONFIG_MISO_PIN 4
159 | #define SPI2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
160 |
161 | #define SPI2_INSTANCE_INDEX (SPI0_ENABLED + SPI1_ENABLED)
162 | #endif
163 |
164 | #define SPI_COUNT (SPI0_ENABLED + SPI1_ENABLED + SPI2_ENABLED)
165 |
166 | /* SPIS */
167 | #define SPIS0_ENABLED 0
168 |
169 | #if (SPIS0_ENABLED == 1)
170 | #define SPIS0_CONFIG_SCK_PIN 2
171 | #define SPIS0_CONFIG_MOSI_PIN 3
172 | #define SPIS0_CONFIG_MISO_PIN 4
173 | #define SPIS0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
174 |
175 | #define SPIS0_INSTANCE_INDEX 0
176 | #endif
177 |
178 | #define SPIS1_ENABLED 0
179 |
180 | #if (SPIS1_ENABLED == 1)
181 | #define SPIS1_CONFIG_SCK_PIN 2
182 | #define SPIS1_CONFIG_MOSI_PIN 3
183 | #define SPIS1_CONFIG_MISO_PIN 4
184 | #define SPIS1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
185 |
186 | #define SPIS1_INSTANCE_INDEX SPIS0_ENABLED
187 | #endif
188 |
189 | #define SPIS2_ENABLED 0
190 |
191 | #if (SPIS2_ENABLED == 1)
192 | #define SPIS2_CONFIG_SCK_PIN 2
193 | #define SPIS2_CONFIG_MOSI_PIN 3
194 | #define SPIS2_CONFIG_MISO_PIN 4
195 | #define SPIS2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
196 |
197 | #define SPIS2_INSTANCE_INDEX (SPIS0_ENABLED + SPIS1_ENABLED)
198 | #endif
199 |
200 | #define SPIS_COUNT (SPIS0_ENABLED + SPIS1_ENABLED + SPIS2_ENABLED)
201 |
202 | /* UART */
203 | #define UART0_ENABLED 1
204 |
205 | #if (UART0_ENABLED == 1)
206 | #define UART0_CONFIG_HWFC NRF_UART_HWFC_DISABLED
207 | #define UART0_CONFIG_PARITY NRF_UART_PARITY_EXCLUDED
208 | #define UART0_CONFIG_BAUDRATE NRF_UART_BAUDRATE_38400
209 | #define UART0_CONFIG_PSEL_TXD 9
210 | #define UART0_CONFIG_PSEL_RXD 11
211 | #define UART0_CONFIG_PSEL_CTS 10
212 | #define UART0_CONFIG_PSEL_RTS 8
213 | #define UART0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
214 | #ifdef NRF52
215 | #define UART0_CONFIG_USE_EASY_DMA false
216 | //Compile time flag
217 | #define UART_EASY_DMA_SUPPORT 1
218 | #define UART_LEGACY_SUPPORT 1
219 | #endif //NRF52
220 | #endif
221 |
222 | #define TWI0_ENABLED 0
223 |
224 | #if (TWI0_ENABLED == 1)
225 | #define TWI0_CONFIG_FREQUENCY NRF_TWI_FREQ_100K
226 | #define TWI0_CONFIG_SCL 0
227 | #define TWI0_CONFIG_SDA 1
228 | #define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
229 |
230 | #define TWI0_INSTANCE_INDEX 0
231 | #endif
232 |
233 | #define TWI1_ENABLED 0
234 |
235 | #if (TWI1_ENABLED == 1)
236 | #define TWI1_CONFIG_FREQUENCY NRF_TWI_FREQ_100K
237 | #define TWI1_CONFIG_SCL 0
238 | #define TWI1_CONFIG_SDA 1
239 | #define TWI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
240 |
241 | #define TWI1_INSTANCE_INDEX (TWI0_ENABLED)
242 | #endif
243 |
244 | #define TWI_COUNT (TWI0_ENABLED+TWI1_ENABLED)
245 |
246 | /* TWIS */
247 | #define TWIS0_ENABLED 0
248 |
249 | #if (TWIS0_ENABLED == 1)
250 | #define TWIS0_CONFIG_ADDR0 0
251 | #define TWIS0_CONFIG_ADDR1 0 /* 0: Disabled */
252 | #define TWIS0_CONFIG_SCL 0
253 | #define TWIS0_CONFIG_SDA 1
254 | #define TWIS0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
255 |
256 | #define TWIS0_INSTANCE_INDEX 0
257 | #endif
258 |
259 | #define TWIS1_ENABLED 0
260 |
261 | #if (TWIS1_ENABLED == 1)
262 | #define TWIS1_CONFIG_ADDR0 0
263 | #define TWIS1_CONFIG_ADDR1 0 /* 0: Disabled */
264 | #define TWIS1_CONFIG_SCL 0
265 | #define TWIS1_CONFIG_SDA 1
266 | #define TWIS1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
267 |
268 | #define TWIS1_INSTANCE_INDEX (TWIS0_ENABLED)
269 | #endif
270 |
271 | #define TWIS_COUNT (TWIS0_ENABLED + TWIS1_ENABLED)
272 | /* For more documentation see nrf_drv_twis.h file */
273 | #define TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0
274 | /* For more documentation see nrf_drv_twis.h file */
275 | #define TWIS_NO_SYNC_MODE 0
276 | /**
277 | * @brief Definition for patching PAN problems
278 | *
279 | * Set this definition to nonzero value to patch anomalies
280 | * from MPW3 - first lunch microcontroller.
281 | *
282 | * Concerns:
283 | * - PAN-29: TWIS: incorrect bits in ERRORSRC
284 | * - PAN-30: TWIS: STOP task does not work as expected
285 | */
286 | #define NRF_TWIS_PATCH_FOR_MPW3 1
287 |
288 |
289 | /* QDEC */
290 | #define QDEC_ENABLED 0
291 |
292 | #if (QDEC_ENABLED == 1)
293 | #define QDEC_CONFIG_REPORTPER NRF_QDEC_REPORTPER_10
294 | #define QDEC_CONFIG_SAMPLEPER NRF_QDEC_SAMPLEPER_16384us
295 | #define QDEC_CONFIG_PIO_A 1
296 | #define QDEC_CONFIG_PIO_B 2
297 | #define QDEC_CONFIG_PIO_LED 3
298 | #define QDEC_CONFIG_LEDPRE 511
299 | #define QDEC_CONFIG_LEDPOL NRF_QDEC_LEPOL_ACTIVE_HIGH
300 | #define QDEC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
301 | #define QDEC_CONFIG_DBFEN false
302 | #define QDEC_CONFIG_SAMPLE_INTEN false
303 | #endif
304 |
305 | /* SAADC */
306 | #define SAADC_ENABLED 0
307 |
308 | #if (SAADC_ENABLED == 1)
309 | #define SAADC_CONFIG_RESOLUTION NRF_SAADC_RESOLUTION_10BIT
310 | #define SAADC_CONFIG_OVERSAMPLE NRF_SAADC_OVERSAMPLE_DISABLED
311 | #define SAADC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
312 | #endif
313 |
314 | /* LPCOMP */
315 | #define LPCOMP_ENABLED 0
316 |
317 | #if (LPCOMP_ENABLED == 1)
318 | #define LPCOMP_CONFIG_REFERENCE NRF_LPCOMP_REF_SUPPLY_4_8
319 | #define LPCOMP_CONFIG_DETECTION NRF_LPCOMP_DETECT_DOWN
320 | #define LPCOMP_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
321 | #define LPCOMP_CONFIG_INPUT NRF_LPCOMP_INPUT_0
322 | #endif
323 |
324 | /* WDT */
325 | #define WDT_ENABLED 0
326 |
327 | #if (WDT_ENABLED == 1)
328 | #define WDT_CONFIG_BEHAVIOUR NRF_WDT_BEHAVIOUR_RUN_SLEEP
329 | #define WDT_CONFIG_RELOAD_VALUE 2000
330 | #define WDT_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH
331 | #endif
332 |
333 | /* SWI EGU */
334 | #ifdef NRF52
335 | #define EGU_ENABLED 0
336 | #endif
337 |
338 |
339 | #include "nrf_drv_config_validation.h"
340 |
341 | #endif // NRF_DRV_CONFIG_H
342 |
--------------------------------------------------------------------------------
/LICENSE-SOFTWARE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/pcb/libs/bluetooth40-nrf51822.lbr:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 | >NAME
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | >NAME
147 | >VALUE
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
--------------------------------------------------------------------------------
/avrnacl/crypto_hashblocks/sha512.c:
--------------------------------------------------------------------------------
1 | /*
2 | * File: avrnacl_8bitc/crypto_hashblocks/sha512.c
3 | * Author: Michael Hutter, Peter Schwabe
4 | * Version: Wed Aug 6 13:19:40 2014 +0200
5 | * Public Domain
6 | */
7 |
8 | #include "avrnacl.h"
9 | #include "bigint.h"
10 |
11 | typedef struct{
12 | unsigned char v[8];
13 | } myu64;
14 |
15 | static void myu64_load_bigendian(myu64 *r, const unsigned char *x)
16 | {
17 | r->v[7] = x[0];
18 | r->v[6] = x[1];
19 | r->v[5] = x[2];
20 | r->v[4] = x[3];
21 | r->v[3] = x[4];
22 | r->v[2] = x[5];
23 | r->v[1] = x[6];
24 | r->v[0] = x[7];
25 | }
26 |
27 | static void myu64_store_bigendian(unsigned char *r, const myu64 *x)
28 | {
29 | r[7] = x->v[0];
30 | r[6] = x->v[1];
31 | r[5] = x->v[2];
32 | r[4] = x->v[3];
33 | r[3] = x->v[4];
34 | r[2] = x->v[5];
35 | r[1] = x->v[6];
36 | r[0] = x->v[7];
37 | }
38 |
39 |
40 | static void myu64_add(myu64 *r, const myu64 *x, const myu64 *y)
41 | {
42 | bigint_add(r->v, x->v, y->v, 8);
43 | }
44 |
45 | static void myu64_xor(myu64 *r, const myu64 *x, const myu64 *y)
46 | {
47 | unsigned char i;
48 | for(i=0;i<8;i++)
49 | r->v[i] = x->v[i] ^ y->v[i];
50 | }
51 |
52 | static void myu64_and(myu64 *r, const myu64 *x, const myu64 *y)
53 | {
54 | unsigned char i;
55 | for(i=0;i<8;i++)
56 | r->v[i] = x->v[i] & y->v[i];
57 | }
58 |
59 | static void myu64_not(myu64 *r, const myu64 *x)
60 | {
61 | unsigned char i;
62 | for(i=0;i<8;i++)
63 | r->v[i] = ~x->v[i];
64 | }
65 |
66 | static void myu64_ror(myu64 *r, unsigned char n)
67 | {
68 | myu64 t = *r;
69 | unsigned char u = n >> 3;
70 | unsigned char l = n & 7;
71 | unsigned char i;
72 | for(i=0;i<8;i++)
73 | r->v[i] = (t.v[(i+u+1)&7] << (8-l)) | (t.v[(i+u)&7] >> l);
74 | }
75 |
76 | // Works for values 6 and 7 as required, does not work generally
77 | static void myu64_shr(myu64 *r, unsigned char n)
78 | {
79 | unsigned char i;
80 | for(i=0;i<7;i++)
81 | r->v[i] = (r->v[i] >> n) | (r->v[i+1] << (8-n));
82 | r->v[7] >>= n;
83 | }
84 |
85 | static void Ch(myu64 *r, const myu64 *x, const myu64 *y, const myu64 *z)
86 | {
87 | myu64 t;
88 | myu64_and(&t,x,y);
89 | myu64_not(r,x);
90 | myu64_and(r,r,z);
91 | myu64_xor(r,r,&t);
92 | }
93 |
94 | static void Maj(myu64 *r, const myu64 *x, const myu64 *y, const myu64 *z)
95 | {
96 | myu64 t0;
97 | myu64 t1;
98 | myu64_and(&t0,x,y);
99 | myu64_and(&t1,x,z);
100 | myu64_and(r,y,z);
101 | myu64_xor(r,r,&t0);
102 | myu64_xor(r,r,&t1);
103 | }
104 |
105 | static void Sigma0(myu64 *r, const myu64 *x)
106 | {
107 | *r = *x;
108 | myu64 t = *x;
109 | myu64_ror(r, 28);
110 | myu64_ror(&t, 34);
111 | myu64_xor(r, r, &t);
112 | myu64_ror(&t, 5);
113 | myu64_xor(r, r, &t);
114 | }
115 |
116 | static void Sigma1(myu64 *r, const myu64 *x)
117 | {
118 | *r = *x;
119 | myu64 t = *x;
120 | myu64_ror(r, 14);
121 | myu64_ror(&t, 18);
122 | myu64_xor(r, r, &t);
123 | myu64_ror(&t, 23);
124 | myu64_xor(r, r, &t);
125 | }
126 |
127 | static void sigma0(myu64 *r, const myu64 *x)
128 | {
129 | *r = *x;
130 | myu64 t0 = *x;
131 | myu64 t1 = *x;
132 | myu64_ror(r, 1);
133 | myu64_ror(&t0, 8);
134 | myu64_xor(r, r, &t0);
135 | myu64_shr(&t1, 7);
136 | myu64_xor(r, r, &t1);
137 | }
138 |
139 | static void sigma1(myu64 *r, const myu64 *x)
140 | {
141 | *r = *x;
142 | myu64 t0 = *x;
143 | myu64 t1 = *x;
144 | myu64_ror(r, 19);
145 | myu64_ror(&t0, 61);
146 | myu64_xor(r, r, &t0);
147 | myu64_shr(&t1, 6);
148 | myu64_xor(r, r, &t1);
149 | }
150 |
151 | static void M(myu64 *w0, const myu64 *w14, const myu64 *w9, const myu64 *w1)
152 | {
153 | myu64 t0, t1;
154 | sigma0(&t0, w1);
155 | sigma1(&t1, w14);
156 | myu64_add(w0, w0, w9);
157 | myu64_add(w0, w0, &t0);
158 | myu64_add(w0, w0, &t1);
159 | }
160 |
161 | static void expand(myu64 *w0, myu64 *w1, myu64 *w2, myu64 *w3, myu64 *w4, myu64 *w5, myu64 *w6, myu64 *w7,
162 | myu64 *w8, myu64 *w9, myu64 *w10, myu64 *w11, myu64 *w12, myu64 *w13, myu64 *w14, myu64 *w15)
163 | {
164 | M(w0 ,w14,w9 ,w1 );
165 | M(w1 ,w15,w10,w2 );
166 | M(w2 ,w0 ,w11,w3 );
167 | M(w3 ,w1 ,w12,w4 );
168 | M(w4 ,w2 ,w13,w5 );
169 | M(w5 ,w3 ,w14,w6 );
170 | M(w6 ,w4 ,w15,w7 );
171 | M(w7 ,w5 ,w0 ,w8 );
172 | M(w8 ,w6 ,w1 ,w9 );
173 | M(w9 ,w7 ,w2 ,w10);
174 | M(w10,w8 ,w3 ,w11);
175 | M(w11,w9 ,w4 ,w12);
176 | M(w12,w10,w5 ,w13);
177 | M(w13,w11,w6 ,w14);
178 | M(w14,w12,w7 ,w15);
179 | M(w15,w13,w8 ,w0 );
180 | }
181 |
182 | static void myF(myu64 *a, myu64 *b, myu64 *c, myu64 *d, myu64 *e, myu64 *f, myu64 *g, myu64 *h, const myu64 *w, const myu64 *k)
183 | {
184 | myu64 t, t1, t2;
185 | Ch(&t, e, f, g);
186 | Sigma1(&t1, e);
187 | myu64_add(&t1, &t1, h);
188 | myu64_add(&t1, &t1, &t);
189 | myu64_add(&t1, &t1, k);
190 | myu64_add(&t1, &t1, w);
191 |
192 | Sigma0(&t2, a);
193 | Maj(&t,a,b,c);
194 | myu64_add(&t2, &t2, &t);
195 |
196 | *h = *g;
197 | *g = *f;
198 | *f = *e;
199 | myu64_add(e,d,&t1);
200 | *d = *c;
201 | *c = *b;
202 | *b = *a;
203 | myu64_add(a,&t1,&t2);
204 | }
205 |
206 |
207 | const myu64 roundconstants[80] = {
208 | {{0x22, 0xae, 0x28, 0xd7, 0x98, 0x2f, 0x8a, 0x42}},
209 | {{0xcd, 0x65, 0xef, 0x23, 0x91, 0x44, 0x37, 0x71}},
210 | {{0x2f, 0x3b, 0x4d, 0xec, 0xcf, 0xfb, 0xc0, 0xb5}},
211 | {{0xbc, 0xdb, 0x89, 0x81, 0xa5, 0xdb, 0xb5, 0xe9}},
212 | {{0x38, 0xb5, 0x48, 0xf3, 0x5b, 0xc2, 0x56, 0x39}},
213 | {{0x19, 0xd0, 0x05, 0xb6, 0xf1, 0x11, 0xf1, 0x59}},
214 | {{0x9b, 0x4f, 0x19, 0xaf, 0xa4, 0x82, 0x3f, 0x92}},
215 | {{0x18, 0x81, 0x6d, 0xda, 0xd5, 0x5e, 0x1c, 0xab}},
216 | {{0x42, 0x02, 0x03, 0xa3, 0x98, 0xaa, 0x07, 0xd8}},
217 | {{0xbe, 0x6f, 0x70, 0x45, 0x01, 0x5b, 0x83, 0x12}},
218 | {{0x8c, 0xb2, 0xe4, 0x4e, 0xbe, 0x85, 0x31, 0x24}},
219 | {{0xe2, 0xb4, 0xff, 0xd5, 0xc3, 0x7d, 0x0c, 0x55}},
220 | {{0x6f, 0x89, 0x7b, 0xf2, 0x74, 0x5d, 0xbe, 0x72}},
221 | {{0xb1, 0x96, 0x16, 0x3b, 0xfe, 0xb1, 0xde, 0x80}},
222 | {{0x35, 0x12, 0xc7, 0x25, 0xa7, 0x06, 0xdc, 0x9b}},
223 | {{0x94, 0x26, 0x69, 0xcf, 0x74, 0xf1, 0x9b, 0xc1}},
224 | {{0xd2, 0x4a, 0xf1, 0x9e, 0xc1, 0x69, 0x9b, 0xe4}},
225 | {{0xe3, 0x25, 0x4f, 0x38, 0x86, 0x47, 0xbe, 0xef}},
226 | {{0xb5, 0xd5, 0x8c, 0x8b, 0xc6, 0x9d, 0xc1, 0x0f}},
227 | {{0x65, 0x9c, 0xac, 0x77, 0xcc, 0xa1, 0x0c, 0x24}},
228 | {{0x75, 0x02, 0x2b, 0x59, 0x6f, 0x2c, 0xe9, 0x2d}},
229 | {{0x83, 0xe4, 0xa6, 0x6e, 0xaa, 0x84, 0x74, 0x4a}},
230 | {{0xd4, 0xfb, 0x41, 0xbd, 0xdc, 0xa9, 0xb0, 0x5c}},
231 | {{0xb5, 0x53, 0x11, 0x83, 0xda, 0x88, 0xf9, 0x76}},
232 | {{0xab, 0xdf, 0x66, 0xee, 0x52, 0x51, 0x3e, 0x98}},
233 | {{0x10, 0x32, 0xb4, 0x2d, 0x6d, 0xc6, 0x31, 0xa8}},
234 | {{0x3f, 0x21, 0xfb, 0x98, 0xc8, 0x27, 0x03, 0xb0}},
235 | {{0xe4, 0x0e, 0xef, 0xbe, 0xc7, 0x7f, 0x59, 0xbf}},
236 | {{0xc2, 0x8f, 0xa8, 0x3d, 0xf3, 0x0b, 0xe0, 0xc6}},
237 | {{0x25, 0xa7, 0x0a, 0x93, 0x47, 0x91, 0xa7, 0xd5}},
238 | {{0x6f, 0x82, 0x03, 0xe0, 0x51, 0x63, 0xca, 0x06}},
239 | {{0x70, 0x6e, 0x0e, 0x0a, 0x67, 0x29, 0x29, 0x14}},
240 | {{0xfc, 0x2f, 0xd2, 0x46, 0x85, 0x0a, 0xb7, 0x27}},
241 | {{0x26, 0xc9, 0x26, 0x5c, 0x38, 0x21, 0x1b, 0x2e}},
242 | {{0xed, 0x2a, 0xc4, 0x5a, 0xfc, 0x6d, 0x2c, 0x4d}},
243 | {{0xdf, 0xb3, 0x95, 0x9d, 0x13, 0x0d, 0x38, 0x53}},
244 | {{0xde, 0x63, 0xaf, 0x8b, 0x54, 0x73, 0x0a, 0x65}},
245 | {{0xa8, 0xb2, 0x77, 0x3c, 0xbb, 0x0a, 0x6a, 0x76}},
246 | {{0xe6, 0xae, 0xed, 0x47, 0x2e, 0xc9, 0xc2, 0x81}},
247 | {{0x3b, 0x35, 0x82, 0x14, 0x85, 0x2c, 0x72, 0x92}},
248 | {{0x64, 0x03, 0xf1, 0x4c, 0xa1, 0xe8, 0xbf, 0xa2}},
249 | {{0x01, 0x30, 0x42, 0xbc, 0x4b, 0x66, 0x1a, 0xa8}},
250 | {{0x91, 0x97, 0xf8, 0xd0, 0x70, 0x8b, 0x4b, 0xc2}},
251 | {{0x30, 0xbe, 0x54, 0x06, 0xa3, 0x51, 0x6c, 0xc7}},
252 | {{0x18, 0x52, 0xef, 0xd6, 0x19, 0xe8, 0x92, 0xd1}},
253 | {{0x10, 0xa9, 0x65, 0x55, 0x24, 0x06, 0x99, 0xd6}},
254 | {{0x2a, 0x20, 0x71, 0x57, 0x85, 0x35, 0x0e, 0xf4}},
255 | {{0xb8, 0xd1, 0xbb, 0x32, 0x70, 0xa0, 0x6a, 0x10}},
256 | {{0xc8, 0xd0, 0xd2, 0xb8, 0x16, 0xc1, 0xa4, 0x19}},
257 | {{0x53, 0xab, 0x41, 0x51, 0x08, 0x6c, 0x37, 0x1e}},
258 | {{0x99, 0xeb, 0x8e, 0xdf, 0x4c, 0x77, 0x48, 0x27}},
259 | {{0xa8, 0x48, 0x9b, 0xe1, 0xb5, 0xbc, 0xb0, 0x34}},
260 | {{0x63, 0x5a, 0xc9, 0xc5, 0xb3, 0x0c, 0x1c, 0x39}},
261 | {{0xcb, 0x8a, 0x41, 0xe3, 0x4a, 0xaa, 0xd8, 0x4e}},
262 | {{0x73, 0xe3, 0x63, 0x77, 0x4f, 0xca, 0x9c, 0x5b}},
263 | {{0xa3, 0xb8, 0xb2, 0xd6, 0xf3, 0x6f, 0x2e, 0x68}},
264 | {{0xfc, 0xb2, 0xef, 0x5d, 0xee, 0x82, 0x8f, 0x74}},
265 | {{0x60, 0x2f, 0x17, 0x43, 0x6f, 0x63, 0xa5, 0x78}},
266 | {{0x72, 0xab, 0xf0, 0xa1, 0x14, 0x78, 0xc8, 0x84}},
267 | {{0xec, 0x39, 0x64, 0x1a, 0x08, 0x02, 0xc7, 0x8c}},
268 | {{0x28, 0x1e, 0x63, 0x23, 0xfa, 0xff, 0xbe, 0x90}},
269 | {{0xe9, 0xbd, 0x82, 0xde, 0xeb, 0x6c, 0x50, 0xa4}},
270 | {{0x15, 0x79, 0xc6, 0xb2, 0xf7, 0xa3, 0xf9, 0xbe}},
271 | {{0x2b, 0x53, 0x72, 0xe3, 0xf2, 0x78, 0x71, 0xc6}},
272 | {{0x9c, 0x61, 0x26, 0xea, 0xce, 0x3e, 0x27, 0xca}},
273 | {{0x07, 0xc2, 0xc0, 0x21, 0xc7, 0xb8, 0x86, 0xd1}},
274 | {{0x1e, 0xeb, 0xe0, 0xcd, 0xd6, 0x7d, 0xda, 0xea}},
275 | {{0x78, 0xd1, 0x6e, 0xee, 0x7f, 0x4f, 0x7d, 0xf5}},
276 | {{0xba, 0x6f, 0x17, 0x72, 0xaa, 0x67, 0xf0, 0x06}},
277 | {{0xa6, 0x98, 0xc8, 0xa2, 0xc5, 0x7d, 0x63, 0x0a}},
278 | {{0xae, 0x0d, 0xf9, 0xbe, 0x04, 0x98, 0x3f, 0x11}},
279 | {{0x1b, 0x47, 0x1c, 0x13, 0x35, 0x0b, 0x71, 0x1b}},
280 | {{0x84, 0x7d, 0x04, 0x23, 0xf5, 0x77, 0xdb, 0x28}},
281 | {{0x93, 0x24, 0xc7, 0x40, 0x7b, 0xab, 0xca, 0x32}},
282 | {{0xbc, 0xbe, 0xc9, 0x15, 0x0a, 0xbe, 0x9e, 0x3c}},
283 | {{0x4c, 0x0d, 0x10, 0x9c, 0xc4, 0x67, 0x1d, 0x43}},
284 | {{0xb6, 0x42, 0x3e, 0xcb, 0xbe, 0xd4, 0xc5, 0x4c}},
285 | {{0x2a, 0x7e, 0x65, 0xfc, 0x9c, 0x29, 0x7f, 0x59}},
286 | {{0xec, 0xfa, 0xd6, 0x3a, 0xab, 0x6f, 0xcb, 0x5f}},
287 | {{0x17, 0x58, 0x47, 0x4a, 0x8c, 0x19, 0x44, 0x6c}}};
288 |
289 | int crypto_hashblocks_sha512(
290 | unsigned char *statebytes,
291 | const unsigned char *in,crypto_uint16 inlen
292 | )
293 | {
294 | myu64 state[8];
295 | myu64 a;
296 | myu64 b;
297 | myu64 c;
298 | myu64 d;
299 | myu64 e;
300 | myu64 f;
301 | myu64 g;
302 | myu64 h;
303 | unsigned char i;
304 |
305 | myu64 w[16];
306 |
307 | myu64_load_bigendian(&a, statebytes + 0); state[0] = a;
308 | myu64_load_bigendian(&b, statebytes + 8); state[1] = b;
309 | myu64_load_bigendian(&c, statebytes + 16); state[2] = c;
310 | myu64_load_bigendian(&d, statebytes + 24); state[3] = d;
311 | myu64_load_bigendian(&e, statebytes + 32); state[4] = e;
312 | myu64_load_bigendian(&f, statebytes + 40); state[5] = f;
313 | myu64_load_bigendian(&g, statebytes + 48); state[6] = g;
314 | myu64_load_bigendian(&h, statebytes + 56); state[7] = h;
315 |
316 | while (inlen >= 128)
317 | {
318 | for(i=0;i<16;i++)
319 | myu64_load_bigendian(w+i, in + 8*i);
320 |
321 | for(i=0;i<16;i++)
322 | myF(&a, &b, &c, &d, &e, &f, &g, &h, w+i, roundconstants+i);
323 |
324 | expand( w+0, w+1, w+2, w+3, w+4, w+5, w+6, w+7, w+8, w+9, w+10, w+11, w+12, w+13, w+14, w+15);
325 |
326 | for(i=0;i<16;i++)
327 | myF(&a, &b, &c, &d, &e, &f, &g, &h, w+i, roundconstants+i+16);
328 |
329 | expand( w+0, w+1, w+2, w+3, w+4, w+5, w+6, w+7, w+8, w+9, w+10, w+11, w+12, w+13, w+14, w+15);
330 |
331 | for(i=0;i<16;i++)
332 | myF(&a, &b, &c, &d, &e, &f, &g, &h, w+i, roundconstants+i+32);
333 |
334 | expand( w+0, w+1, w+2, w+3, w+4, w+5, w+6, w+7, w+8, w+9, w+10, w+11, w+12, w+13, w+14, w+15);
335 |
336 | for(i=0;i<16;i++)
337 | myF(&a, &b, &c, &d, &e, &f, &g, &h, w+i, roundconstants+i+48);
338 |
339 | expand( w+0, w+1, w+2, w+3, w+4, w+5, w+6, w+7, w+8, w+9, w+10, w+11, w+12, w+13, w+14, w+15);
340 |
341 | for(i=0;i<16;i++)
342 | myF(&a, &b, &c, &d, &e, &f, &g, &h, w+i, roundconstants+i+64);
343 |
344 | myu64_add(&a, &a, state+0);
345 | myu64_add(&b, &b, state+1);
346 | myu64_add(&c, &c, state+2);
347 | myu64_add(&d, &d, state+3);
348 | myu64_add(&e, &e, state+4);
349 | myu64_add(&f, &f, state+5);
350 | myu64_add(&g, &g, state+6);
351 | myu64_add(&h, &h, state+7);
352 |
353 | state[0] = a;
354 | state[1] = b;
355 | state[2] = c;
356 | state[3] = d;
357 | state[4] = e;
358 | state[5] = f;
359 | state[6] = g;
360 | state[7] = h;
361 |
362 | in += 128;
363 | inlen -= 128;
364 | }
365 |
366 | myu64_store_bigendian(statebytes + 0,state+0);
367 | myu64_store_bigendian(statebytes + 8,state+1);
368 | myu64_store_bigendian(statebytes + 16,state+2);
369 | myu64_store_bigendian(statebytes + 24,state+3);
370 | myu64_store_bigendian(statebytes + 32,state+4);
371 | myu64_store_bigendian(statebytes + 40,state+5);
372 | myu64_store_bigendian(statebytes + 48,state+6);
373 | myu64_store_bigendian(statebytes + 56,state+7);
374 |
375 | return inlen;
376 | }
377 |
--------------------------------------------------------------------------------