Skip to content

Commit 10ab0be

Browse files
authored
Merge pull request #152 from cyyber/master
Added support for Go
2 parents 7420fdb + 5356d0c commit 10ab0be

19 files changed

+1033
-4
lines changed

.circleci/config.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ jobs:
1818
- run: git submodule update --init --recursive
1919
- run: python3 setup.py test
2020

21+
test_golang:
22+
docker:
23+
- image: zondax/qrl-build-images:xenial-qrllib
24+
steps:
25+
- checkout
26+
- run: add-apt-repository ppa:ubuntu-toolchain-r/test
27+
- run: apt update
28+
- run: apt install g++-7 -y
29+
- run: update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7
30+
- run: git submodule update --init --recursive
31+
32+
- run: cd / && curl -O https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz && tar zxvf go1.8.linux-amd64.tar.gz
33+
- run:
34+
name: Setting up Environment Variables for Golang
35+
command: |
36+
echo 'export GOROOT="/go"' >> $BASH_ENV
37+
echo 'export PATH="$PATH:/go/bin/"' >> $BASH_ENV
38+
39+
- run: go get github.com/magiconair/properties/assert
40+
- run: mkdir -p ~/go/src/github.com/theQRL/qrllib/
41+
- run: cp -r . ~/go/src/github.com/theQRL/qrllib/
42+
- run: cd ~/go/src/github.com/theQRL/qrllib/ && cmake -DBUILD_GO=ON
43+
- run: cd ~/go/src/github.com/theQRL/qrllib/ && make
44+
- run: cd ~/go/src/github.com/theQRL/qrllib/tests/golang/tests/ && go test -v
45+
2146
build_emscripten:
2247
docker:
2348
- image: zondax/qrl-build-images:emscripten
@@ -97,6 +122,11 @@ workflows:
97122
tags:
98123
only: /.*/
99124

125+
- test_golang:
126+
filters:
127+
tags:
128+
only: /.*/
129+
100130
- build_emscripten:
101131
filters:
102132
tags:

CMakeLists.txt

Lines changed: 152 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ set(CMAKE_VERBOSE_MAKEFILE TRUE)
1313
set(CMAKE_ERROR_DEPRECATED FALSE)
1414
set(CMAKE_WARN_DEPRECATED FALSE)
1515

16-
option(BUILD_TESTS "Enable tests" ON )
17-
option(BUILD_GO "Enable go wrapper" OFF )
16+
option(BUILD_TESTS "Enable tests" ON)
17+
option(BUILD_GO "Enable go wrapper" OFF)
1818
option(BUILD_PYTHON "Enable python wrapper" OFF)
1919
option(BUILD_WEBASSEMBLY "Enable emscripten build" OFF)
2020

@@ -382,6 +382,156 @@ if (BUILD_PYTHON)
382382

383383
endif ()
384384

385+
## SWIG + API - Go related stuff
386+
if (BUILD_GO)
387+
message(STATUS "Go wrapper enabled")
388+
389+
unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
390+
391+
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
392+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
393+
endif ()
394+
395+
set(language go)
396+
397+
set(CMAKE_SWIG_OUTDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/goqrllib/goqrllib)
398+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/goqrllib/goqrllib)
399+
400+
set(SWIG_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/api/pyqrllib.i)
401+
set_source_files_properties(${SWIG_INTERFACE} PROPERTIES CPLUSPLUS ON)
402+
set_property(SOURCE ${SWIG_INTERFACE} PROPERTY SWIG_FLAGS "-includeall" "-ignoremissing" "-cgo" "-intgosize" "64" "-c++")
403+
message(STATUS "CMAKE_SWIG_OUTDIR: " ${CMAKE_SWIG_OUTDIR})
404+
message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: " ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
405+
406+
# Intentionally use a deprecated version to provide support for the raspberry pi
407+
SWIG_ADD_MODULE(goqrllib
408+
${language}
409+
${SWIG_INTERFACE}
410+
${LIB_QRL_SRC}
411+
${LIBXMSSALT_SRC}
412+
)
413+
414+
SWIG_LINK_LIBRARIES(goqrllib
415+
shasha
416+
${SWIG_LANG_LIBRARIES})
417+
418+
include_directories(
419+
${LIB_QRL_INCLUDES}
420+
${LIB_SHASHA_INCLUDES}
421+
)
422+
423+
add_custom_command(TARGET ${SWIG_MODULE_goqrllib_REAL_NAME}
424+
POST_BUILD
425+
COMMENT "Moving SWIG files to output dir"
426+
COMMAND ${CMAKE_COMMAND} -E
427+
copy_if_different $<TARGET_FILE:${SWIG_MODULE_goqrllib_REAL_NAME}>
428+
${CMAKE_CURRENT_SOURCE_DIR}/goqrllib/goqrllib/$<TARGET_LINKER_FILE_NAME:${SWIG_MODULE_goqrllib_REAL_NAME}>
429+
COMMENT "Updating goqrllib flags"
430+
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/scripts/update_goqrllib_flags.sh ${CMAKE_CURRENT_SOURCE_DIR}
431+
)
432+
433+
#add_custom_command(TARGET ${SWIG_MODULE_goqrllib_REAL_NAME}
434+
# POST_BUILD
435+
# COMMENT ${swig_extra_generated_files}
436+
# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${swig_extra_generated_files} ${CMAKE_CURRENT_SOURCE_DIR}/goqrllib/pyqrllib.go
437+
# )
438+
439+
###################################################
440+
# Dilithium
441+
unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
442+
443+
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
444+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
445+
endif ()
446+
447+
set(CMAKE_SWIG_OUTDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/goqrllib/dilithium)
448+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/goqrllib/dilithium)
449+
450+
451+
set(SWIG_INTERFACE src/api/dilithium.i)
452+
set_source_files_properties(${SWIG_INTERFACE} PROPERTIES CPLUSPLUS ON)
453+
set_property(SOURCE ${SWIG_INTERFACE} PROPERTY SWIG_FLAGS "-includeall" "-ignoremissing" "-cgo" "-intgosize" "64" "-c++")
454+
message(STATUS "CMAKE_SWIG_OUTDIR: " ${CMAKE_SWIG_OUTDIR})
455+
message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: " ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
456+
457+
set(SWIG_INTERFACE
458+
src/api/dilithium.i)
459+
460+
include_directories(
461+
${LIB_DILITHIUM_INCLUDES}
462+
)
463+
464+
SWIG_ADD_MODULE(godilithium
465+
${language}
466+
${SWIG_INTERFACE}
467+
${LIB_DILITHIUM_SRC}
468+
${REF_DILITHIUM_SRC}
469+
)
470+
471+
SWIG_LINK_LIBRARIES(godilithium
472+
${SWIG_LANG_LIBRARIES})
473+
474+
add_custom_command(TARGET ${SWIG_MODULE_godilithium_REAL_NAME}
475+
POST_BUILD
476+
COMMENT "Moving SWIG files to output dir"
477+
COMMAND ${CMAKE_COMMAND} -E
478+
copy_if_different $<TARGET_FILE:${SWIG_MODULE_godilithium_REAL_NAME}>
479+
${CMAKE_CURRENT_SOURCE_DIR}/goqrllib/dilithium/$<TARGET_LINKER_FILE_NAME:${SWIG_MODULE_godilithium_REAL_NAME}>
480+
COMMENT "Updating godilithium flags"
481+
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/scripts/update_godilithium_flags.sh ${CMAKE_CURRENT_SOURCE_DIR}
482+
)
483+
484+
#add_custom_command(TARGET ${SWIG_MODULE_godilithium_REAL_NAME}
485+
# POST_BUILD
486+
# COMMENT ${swig_extra_generated_files}
487+
# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${swig_extra_generated_files} ${CMAKE_CURRENT_SOURCE_DIR}/goqrllib/godilithium.go
488+
# )
489+
490+
491+
# Kyber
492+
unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
493+
494+
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
495+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
496+
endif ()
497+
498+
set(CMAKE_SWIG_OUTDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/goqrllib/kyber)
499+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/goqrllib/kyber)
500+
501+
set(SWIG_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/api/kyber.i)
502+
set_source_files_properties(${SWIG_INTERFACE} PROPERTIES CPLUSPLUS ON)
503+
set_property(SOURCE ${SWIG_INTERFACE} PROPERTY SWIG_FLAGS "-includeall" "-ignoremissing" "-cgo" "-intgosize" "64" "-c++")
504+
message(STATUS "CMAKE_SWIG_OUTDIR: " ${CMAKE_SWIG_OUTDIR})
505+
message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: " ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
506+
507+
SWIG_ADD_MODULE(gokyber
508+
${language}
509+
${SWIG_INTERFACE}
510+
${LIB_KYBER_SRC}
511+
${REF_KYBER_SRC}
512+
)
513+
514+
SWIG_LINK_LIBRARIES(gokyber
515+
${SWIG_LANG_LIBRARIES})
516+
517+
add_custom_command(TARGET ${SWIG_MODULE_gokyber_REAL_NAME}
518+
POST_BUILD
519+
COMMENT "Moving SWIG files to output dir"
520+
COMMAND ${CMAKE_COMMAND} -E
521+
copy_if_different $<TARGET_FILE:${SWIG_MODULE_gokyber_REAL_NAME}>
522+
${CMAKE_CURRENT_SOURCE_DIR}/goqrllib/kyber/$<TARGET_LINKER_FILE_NAME:${SWIG_MODULE_gokyber_REAL_NAME}>
523+
COMMENT "Updating gokyber flags"
524+
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/scripts/update_gokyber_flags.sh ${CMAKE_CURRENT_SOURCE_DIR}
525+
)
526+
527+
#add_custom_command(TARGET ${SWIG_MODULE_gokyber_REAL_NAME}
528+
# POST_BUILD
529+
# COMMENT ${swig_extra_generated_files}
530+
# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${swig_extra_generated_files} ${CMAKE_CURRENT_SOURCE_DIR}/goqrllib/gokyber.go
531+
# )
532+
533+
endif ()
534+
385535
if (BUILD_WEBASSEMBLY)
386536
set(JS_QRL_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/jswrapper/jsqrlwrapper.cpp)
387537

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
mv $1/goqrllib/dilithium/dilithium.go $1/goqrllib/dilithium/temp.go
3+
sed '/#define intgo swig_intgo/i #cgo LDFLAGS: '$1'/goqrllib/dilithium/godilithium.so\n#cgo CXXFLAGS: -I'$1'/src -I'$1'/deps\n' $1/goqrllib/dilithium/temp.go > $1/goqrllib/dilithium/dilithium.go
4+
rm $1/goqrllib/dilithium/temp.go

scripts/update_gokyber_flags.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
mv $1/goqrllib/kyber/kyber.go $1/goqrllib/kyber/temp.go
3+
sed '/#define intgo swig_intgo/i #cgo LDFLAGS: '$1'/goqrllib/kyber/gokyber.so\n#cgo CXXFLAGS: -I'$1'/src -I'$1'/deps\n' $1/goqrllib/kyber/temp.go > $1/goqrllib/kyber/kyber.go
4+
rm $1/goqrllib/kyber/temp.go

scripts/update_goqrllib_flags.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
mv $1/goqrllib/goqrllib/goqrllib.go $1/goqrllib/goqrllib/temp.go
3+
sed '/#define intgo swig_intgo/i #cgo LDFLAGS: '$1'/goqrllib/goqrllib/goqrllib.so\n#cgo CXXFLAGS: -I'$1'/src -I'$1'/deps\n' $1/goqrllib/goqrllib/temp.go > $1/goqrllib/goqrllib/goqrllib.go
4+
rm $1/goqrllib/goqrllib/temp.go

src/api/dilithium.i

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
%include "std_shared_ptr.i"
1212
%include "exception.i"
1313

14+
#if defined(SWIGPYTHON)
1415
%{
1516
SWIGEXPORT void HandleAllExceptions()
1617
{
@@ -40,6 +41,15 @@ SWIGEXPORT void HandleAllExceptions()
4041
SWIG_fail;
4142
}
4243
}
44+
#else
45+
%exception {
46+
try { $action }
47+
catch (std::exception &e) {
48+
_swig_gopanic(e.what());
49+
}
50+
}
51+
52+
#endif
4353

4454

4555
%array_class(unsigned char, ucharCArray)

src/api/kyber.i

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
%include "std_shared_ptr.i"
1212
%include "exception.i"
1313

14+
#if defined(SWIGPYTHON)
1415
%{
1516
SWIGEXPORT void HandleAllExceptions()
1617
{
@@ -40,6 +41,15 @@ SWIGEXPORT void HandleAllExceptions()
4041
SWIG_fail;
4142
}
4243
}
44+
#else
45+
%exception {
46+
try { $action }
47+
catch (std::exception &e) {
48+
_swig_gopanic(e.what());
49+
}
50+
}
51+
52+
#endif
4353

4454
%array_class(unsigned char, ucharCArray)
4555
%array_class(uint, uintCArray)

src/api/pyqrllib.i

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
%include "std_shared_ptr.i"
1212
%include "exception.i"
1313

14+
#if defined(SWIGPYTHON)
1415
%{
1516
SWIGEXPORT void HandleAllExceptions()
1617
{
@@ -40,6 +41,15 @@ SWIGEXPORT void HandleAllExceptions()
4041
SWIG_fail;
4142
}
4243
}
44+
#else
45+
%exception {
46+
try { $action }
47+
catch (std::exception &e) {
48+
_swig_gopanic(e.what());
49+
}
50+
}
51+
52+
#endif
4353

4454
%array_class(unsigned char, ucharCArray)
4555
%array_class(uint, uintCArray)
@@ -55,13 +65,19 @@ namespace std {
5565
%template(_string_list_list) vector<vector<unsigned char>>;
5666
}
5767

68+
#if defined(SWIGPYTHON)
5869
%shared_ptr(XmssBase)
5970
%shared_ptr(XmssBasic)
6071
%shared_ptr(XmssFast)
72+
#endif
6173

6274
// %array_functions(uint32_t, uint32ArrayRaw)
6375

76+
#if defined(SWIGPYTHON)
6477
%module pyqrllib
78+
#else
79+
%module goqrllib
80+
#endif
6581
%{
6682
#include "qrl/misc.h"
6783
#include "qrl/hashing.h"

src/qrl/qrlHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <vector>
77
#include <cstdint>
8-
#include <qrlDescriptor.h>
8+
#include "qrlDescriptor.h"
99
#include <PicoSHA2/picosha2.h>
1010
#include <stdexcept>
1111
#include "misc.h"

src/xmss-alt/xmss_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void xmss_set_params(xmss_params *params, uint32_t n, uint32_t h, uint32_t w, ui
2323

2424
void to_byte(unsigned char *output, unsigned long long in, uint32_t bytes);
2525

26-
void hexdump(const unsigned char *a, size_t len);
26+
// void hexdump(const unsigned char *a, size_t len); # Unimplemented
2727

2828
void l_tree(eHashFunction hash_func,
2929
const wots_params *params,

0 commit comments

Comments
 (0)