add cmake example tie in
parent
b48d52f8bc
commit
82e110815f
|
@ -0,0 +1,31 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
|
||||
project(wolfssl-example)
|
||||
|
||||
message("Example cmake project including wolfSSL and using user_settings.h")
|
||||
|
||||
# add global define to include user_settings.h
|
||||
add_compile_definitions(WOLFSSL_USER_SETTINGS)
|
||||
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
set(WOLFSSL_EXAMPLES OFF)
|
||||
set(WOLFSSL_CRYPT_TESTS OFF)
|
||||
set(WOLFSSL_USER_SETTINGS ON)
|
||||
|
||||
if (CONFIG_BIG_ENDIAN)
|
||||
set(CMAKE_C_BYTE_ORDER BIG_ENDIAN)
|
||||
set(CMAKE_CXX_BYTE_OREDER BIG_ENDIAN)
|
||||
else ()
|
||||
set(CMAKE_C_BYTE_ORDER LITTLE_ENDIAN)
|
||||
set(CMAKE_CXX_BYTE_OREDER LITTLE_ENDIAN)
|
||||
endif()
|
||||
|
||||
include_directories(include)
|
||||
add_subdirectory(wolfssl)
|
||||
|
||||
target_link_libraries(wolfssl PRIVATE
|
||||
)
|
||||
|
||||
# add in our application
|
||||
add_executable(hash myApp.c)
|
||||
target_link_libraries(hash wolfssl)
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
This is an example of adding the wolfSSL library as a subdirectory to a project
|
||||
and using cmake to build.
|
||||
|
||||
## Steps to build:
|
||||
|
||||
\# clone or download the wolfssl bundle and put it in the subdirectory wolfssl
|
||||
git clone https://github.com/wolfssl/wolfssl
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_C_FLAGS=-I../include/
|
||||
make
|
||||
./hash example_string
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _USER_SETTINGS_INCLUDE
|
||||
#define _USER_SETTINGS_INCLUDE
|
||||
|
||||
#define ECC_TIMING_RESISTANT
|
||||
#define WC_RSA_BLINDING
|
||||
|
||||
//add your target specific defines here
|
||||
|
||||
#endif
|
|
@ -0,0 +1,56 @@
|
|||
/* myApp.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL.
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||
*/
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h> /* using user_settings.h for example */
|
||||
#include <wolfssl/wolfcrypt/sha256.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
wc_Sha256 sha;
|
||||
byte digest[WC_SHA256_DIGEST_SIZE];
|
||||
int i, ret;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("%s <to be hashed>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = wc_InitSha256(&sha);
|
||||
if (ret == 0)
|
||||
ret = wc_Sha256Update(&sha, argv[1], (word32)XSTRLEN(argv[1]));
|
||||
if (ret == 0)
|
||||
ret = wc_Sha256Final(&sha, digest);
|
||||
|
||||
if (ret != 0)
|
||||
printf("Error %d\n", ret);
|
||||
|
||||
if (ret == 0) {
|
||||
printf("Hash in hex : ");
|
||||
for (i = 0; i < WC_SHA256_DIGEST_SIZE; i++) {
|
||||
printf("%02X", digest[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue