aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Bech <joakim.bech@linaro.org>2016-06-23 15:07:47 +0200
committerJoakim Bech <joakim.bech@linaro.org>2016-06-23 15:13:58 +0200
commit259bb11c5de7c9569bfc2ce4cab8f3a2b8d2320c (patch)
tree0ee199a3fab3f194222a82ff40aa64b9189f17c4
parente2aee0b781e61776d0157bebf23f2e40f2657838 (diff)
downloadtinycrypt-259bb11c5de7c9569bfc2ce4cab8f3a2b8d2320c.tar.gz
SHA256 OK using TinyCrypt
Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
-rw-r--r--CMakeLists.txt33
-rw-r--r--CMakeToolchain.txt16
-rw-r--r--source/main.c42
3 files changed, 91 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..40a588e
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,33 @@
+# set(CMAKE_TOOLCHAIN_FILE CMakeToolchain.txt)
+project(tinycrypt C)
+
+# Required cmake version
+cmake_minimum_required(VERSION 2.8.12)
+
+# global needed variables
+set(APPLICATION_NAME ${PROJECT_NAME})
+
+set(APPLICATION_VERSION_MAJOR "0")
+set(APPLICATION_VERSION_MINOR "0")
+set(APPLICATION_VERSION_PATCH "1")
+
+set(CMAKE_BUILD_TYPE Debug)
+
+set(APPLICATION_VERSION
+ "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
+
+include_directories(include
+ include/tinycrypt)
+
+set(TINYCRYPT-SRC source/ecc_dsa.c
+ source/ecc.c
+ source/sha256.c
+ source/utils.c
+ source/main.c)
+# add_library(tee SHARED ${LIBTEE-SRC})
+
+# add_definitions(-DBINARY_PREFIX="TEES")
+add_executable(ecc_test ${TINYCRYPT-SRC})
+#target_link_libraries(tee-supplicant tee)
+
+
diff --git a/CMakeToolchain.txt b/CMakeToolchain.txt
new file mode 100644
index 0000000..0691a52
--- /dev/null
+++ b/CMakeToolchain.txt
@@ -0,0 +1,16 @@
+INCLUDE(CMakeForceCompiler)
+
+SET(CMAKE_SYSTEM_NAME Linux)
+
+set(CMAKE_SYSTEM_PROCESSOR arm)
+
+SET(CMAKE_C_COMPILER /home/jbech/toolchains/gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)
+
+SET(CMAKE_FIND_ROOT_PATH /home/jbech/toolchains/gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu)
+
+# search for programs in the build host directories
+SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+# for libraries and headers in the target directories
+SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
diff --git a/source/main.c b/source/main.c
new file mode 100644
index 0000000..12dae49
--- /dev/null
+++ b/source/main.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <ecc.h>
+#include <sha256.h>
+#include <utils.h>
+
+static const char *str = "abc";
+
+void hash_str(const uint8_t *str, uint8_t *digest, uint32_t size)
+{
+ struct tc_sha256_state_struct s;
+
+ memset(&s, 0, sizeof(struct tc_sha256_state_struct));
+
+ printf("Running ecc_test using Tinycrypt\n");
+ if (tc_sha256_init(&s) != TC_SUCCESS)
+ perror("SHA256 init failed\n");
+
+ if (tc_sha256_update(&s, "abc", 3) != TC_SUCCESS)
+ perror("SHA256 update failed\n");
+
+ if (tc_sha256_final(digest, &s) != TC_SUCCESS)
+ perror("SHA256 final failed\n");
+}
+
+void hash_print(const char *str, uint8_t *digest, uint32_t size)
+{
+ int i;
+ printf("Hash of \"%s\" = ", str);
+ for (i = 0; i < size; i++)
+ printf("%02x", digest[i]);
+ printf("\n");
+}
+
+int main(int argc, char argv[])
+{
+ uint8_t d[TC_SHA256_DIGEST_SIZE] = { 0 };
+ hash_str(str, d, sizeof(d));
+ hash_print(str, d, sizeof(d));
+ return 0;
+}