Commit 66cbfd35 authored by manastasova's avatar manastasova
Browse files

Update and Clean

parent 41caf04e
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ DEPS := openssl liboqs oqs-provider

# Default target
all: update install setup openssl liboqs oqs-provider test-oqs compile run
# all: update install setup openssl liboqs oqs-provider test-oqs compile 


# Update and install necessary packages (OS-specific)
@@ -61,6 +60,7 @@ openssl:
			no-ssl no-tls1 no-tls1_1 no-afalgeng \
			no-shared threads -lm && \
		make && \
		make install_sw && \
		echo "OpenSSL cloned and built successfully."; \
	else \
		echo "OpenSSL directory already exists. Skipping clone and build."; \
@@ -73,7 +73,7 @@ liboqs:
		cd $(WORKSPACE) && \
		git clone https://github.com/open-quantum-safe/liboqs  && \
		cd liboqs  && \
		git checkout 0.13.0-release && \
		git checkout 0.13.0 && \
		mkdir build && cd build  && \
		cmake \
			-DBUILD_SHARED_LIBS=ON \
@@ -81,8 +81,10 @@ liboqs:
			-DCMAKE_BUILD_TYPE=Release \
			-DOQS_BUILD_ONLY_LIB=ON \
			-DOQS_DIST_BUILD=ON \
			-DCMAKE_INSTALL_PREFIX=$(BUILD_DIR) \
			..   && \
		make && \
		make install && \
		echo "liboqs cloned and built successfully."; \
	else \
		echo "liboqs directory already exists. Skipping clone and build."; \
@@ -95,13 +97,13 @@ oqs-provider:
		cd $(WORKSPACE) && \
		git clone https://github.com/open-quantum-safe/oqs-provider  && \
		cd oqs-provider && \
		git checkout 0.7.0-release && \
		liboqs_DIR=$(BUILD_DIR) cmake \
			-DOPENSSL_ROOT_DIR=$(WORKSPACE)/openssl/ \
		git checkout 0.7.0 && \
		liboqs_DIR=$(BUILD_DIR)/lib/cmake/liboqs cmake \
			-DOPENSSL_ROOT_DIR=$(BUILD_DIR) \
			-DCMAKE_BUILD_TYPE=Release \
			-S . \
			-B $(BUILD_DIR)  && \
		sudo cmake --build $(BUILD_DIR) ; \
		cmake --build $(BUILD_DIR) ; \
		echo "oqs-provider cloned, built, and configured successfully."; \
	else \
		echo "oqs-provider directory already exists. Skipping clone and build."; \
@@ -115,9 +117,9 @@ test-oqs:
# Compile the project
compile:
	@echo "Compiling the project..."
	gcc -Wall -o etsi-hkex-test main.c crypto.c qshkex.c -lcrypto -loqs \
		-I$(WORKSPACE)/liboqs/build/include/ \
		-L$(BUILD_DIR)/lib
	$(CC) $(CFLAGS) -o etsi-hkex-test main.c crypto.c qshkex.c $(LDFLAGS) \
		-I$(BUILD_DIR)/include \
		-L$(BUILD_DIR)/lib -L$(BUILD_DIR)/lib64
	@echo "Compilation completed. Executable: etsi-hkex-test"


@@ -125,9 +127,9 @@ compile:
run: compile
	@echo "Running etsi-hkex-test..."
ifeq ($(UNAME_S),Linux)
	@export OPENSSL_MODULES=$(BUILD_DIR)/lib  && ./etsi-hkex-test
	@LD_LIBRARY_PATH=$(BUILD_DIR)/lib:$(BUILD_DIR)/lib64 OPENSSL_MODULES=$(BUILD_DIR)/lib ./etsi-hkex-test
else ifeq ($(UNAME_S),Darwin)
	@DYLD_LIBRARY_PATH=$(BUILD_DIR)/lib:$$DYLD_LIBRARY_PATH ./etsi-hkex-test
	@DYLD_LIBRARY_PATH=$(BUILD_DIR)/lib:$$DYLD_LIBRARY_PATH OPENSSL_MODULES=$(BUILD_DIR)/lib ./etsi-hkex-test
endif

# Clean up
+43 −26
Original line number Diff line number Diff line
## TS 103 744 Quantum-safe Hybrid Key Exchanges ##

Informative reference implementation as reported in Annex C of ETSI TS 103 744,
 "CYBER; Quantum-safe Hybrid Key Exchanges. The code is not intended for production use.
 It is intended to be a reference implementation for test.
"CYBER; Quantum-safe Hybrid Key Exchanges". The code is not intended for production use.
It is intended to be a reference implementation for test vector generation.

More information and standards download at the [work item page](https://portal.etsi.org/webapp/WorkProgram/Report_WorkItem.asp?WKI_ID=56901).

@@ -14,23 +14,40 @@
This is not intended for production use. It is intended to be a reference
implementation for test vectors for the specification.

  git clone ssh://git.amazon.com/pkg/Etsi-hkex-test
  git checkout 
### Prerequisites ###

- GCC compiler
- GNU Make
- OpenSSL 3.2 (cloned and built automatically by the Makefile)
- [liboqs](https://github.com/open-quantum-safe/liboqs) v0.13.0 (cloned and built automatically)
- [oqs-provider](https://github.com/open-quantum-safe/oqs-provider) v0.7.0 (cloned and built automatically)

On Linux, the following packages are required and will be installed by `make`:
`git`, `build-essential`, `perl`, `cmake`, `autoconf`, `libtool`, `zlib1g-dev`

### Build instructions ###

This library requires OpenSSL version 3.2.4-dev libcrypto.
To clone and build all dependencies (OpenSSL, liboqs, and oqs-provider), compile, and run:

    To clone and build dependencies (openssl, liboqs, and oqs-provider), run:
    make

    To build and run etsi-hkex-test:
To build and run etsi-hkex-test only (after dependencies are built):

    make run

    Or:
Or compile manually (with appropriate include and library paths):

    gcc -Wall -o etsi-hkex-test main.c crypto.c qshkex.c -lcrypto -loqs
    ./etsi-hkex-test

### Repository ###

Source code is hosted at the ETSI forge:

    git clone https://forge.etsi.org/rep/cyber/103744_QHKEX.git

### License ###

The content of this repository and the files
contained are released under the BSD-3-Clause license.
See the attached LICENSE file or visit https://forge.etsi.org/legal-matters.
+20 −14
Original line number Diff line number Diff line
/*
    This file implements ETSI TC CYBER QSC Quantum-safe Hybrid Key Exchanges
    (Version 1.1.1)
    (Version 1.2.1)

    This is not intended for production use.  It is intended to be a reference
    implementation for test vectors for the specification.

    It uses OpenSSL version 3.4.0 libcrypto.
    It uses OpenSSL version 3.2 libcrypto.

    gcc -Wall -o etsi-hkex-test main.c crypto.c qshkex.c -lcrypto -loqs
    ./etsi-hkex-test
@@ -232,7 +232,7 @@ int test_qhkex_rand_ecdh(int curve, uint8_t *pubA, size_t *PA1length, uint8_t *p
        if (EVP_PKEY_keygen_init(ctxA) <= 0) {
            break;
        }
        if (curve != EVP_PKEY_X25519 || curve != EVP_PKEY_X448) {
        if (curve != EVP_PKEY_X25519 && curve != EVP_PKEY_X448) {
            if (EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctxA, curve) <= 0) {
                break;
            }
@@ -240,11 +240,12 @@ int test_qhkex_rand_ecdh(int curve, uint8_t *pubA, size_t *PA1length, uint8_t *p
        if (EVP_PKEY_keygen(ctxA, &pkeyA) <= 0) {
            break;
        }
        if (curve != EVP_PKEY_X25519 || curve != EVP_PKEY_X448) {
        if (curve != EVP_PKEY_X25519 && curve != EVP_PKEY_X448) {
            if (EVP_PKEY_get_octet_string_param(pkeyA, "pub", pubA, MAX_KEY_BYTE_LEN, &pubA_len) <= 0) {
                break;
            }
        } else {
            pubA_len = MAX_KEY_BYTE_LEN;
            if (EVP_PKEY_get_raw_public_key(pkeyA, pubA, &pubA_len) <= 0) {
                break;
            }
@@ -264,17 +265,20 @@ int test_qhkex_rand_ecdh(int curve, uint8_t *pubA, size_t *PA1length, uint8_t *p
        if (EVP_PKEY_keygen_init(ctxB) <= 0) {
            break;
        }
        if (curve != EVP_PKEY_X25519 && curve != EVP_PKEY_X448) {
            if (EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctxB, curve) <= 0) {
                break;
            }
        }
        if (EVP_PKEY_keygen(ctxB, &pkeyB) <= 0) {
            break;
        }
        if (curve != EVP_PKEY_X25519 || curve != EVP_PKEY_X448) {
        if (curve != EVP_PKEY_X25519 && curve != EVP_PKEY_X448) {
            if (EVP_PKEY_get_octet_string_param(pkeyB, "pub", pubB, MAX_KEY_BYTE_LEN, &pubB_len) <= 0) {
                break;
            }
        } else {
            pubB_len = MAX_KEY_BYTE_LEN;
            if (EVP_PKEY_get_raw_public_key(pkeyB, pubB, &pubB_len) <= 0) {
                break;
            }
@@ -282,6 +286,7 @@ int test_qhkex_rand_ecdh(int curve, uint8_t *pubA, size_t *PA1length, uint8_t *p
        *PB1length = pubB_len;

        // Derive entity A shared secret
        EVP_PKEY_CTX_free(ctxA);
        ctxA = EVP_PKEY_CTX_new(pkeyA, NULL);
        if (!ctxA) {
            break;
@@ -300,6 +305,7 @@ int test_qhkex_rand_ecdh(int curve, uint8_t *pubA, size_t *PA1length, uint8_t *p
        }

        // Derive entity B shared secret
        EVP_PKEY_CTX_free(ctxB);
        ctxB = EVP_PKEY_CTX_new(pkeyB, NULL);
        if (!ctxB) {
            break;
+1 −1
Original line number Diff line number Diff line
/*
    Header file for a reference implementation of
    ETSI TC CYBER QSC Quantum-safe Hybrid Key Exchanges (Version 1.1.1)
    ETSI TC CYBER QSC Quantum-safe Hybrid Key Exchanges (Version 1.2.1)

    This is not intended for production use.  It is intended to be a reference
    implementation for test vectors for the specification.
+12 −11
Original line number Diff line number Diff line
/*
    This file implements ETSI TC CYBER QSC Quantum-safe Hybrid Key Exchanges
    (Version 1.1.1)
    (Version 1.2.1)

    This is not intended for production use.  It is intended to be a reference
    implementation for test vectors for the specification.

    It uses OpenSSL version 1.1.1d libcrypto.
    It uses OpenSSL version 3.2 libcrypto.

    gcc -Wall -o etsi-hkex-test main.c qshkex.c -lcrypto
    gcc -Wall -o etsi-hkex-test main.c crypto.c qshkex.c -lcrypto -loqs
    ./etsi-hkex-test

    Copyright 2020 ETSI. All rights reserved
@@ -16,6 +16,7 @@

#include "qshkex.h"
#include "crypto.h"
#include <stdlib.h>

#define TEST_VECTOR_CNT             12
#define INFO_TEST_VECTOR  "ETSI_QSHKE_TEST_VECTORS_V_1_2"
@@ -1341,7 +1342,7 @@ void ascii_hex_strings_to_uint8(uint8_t *array, uint32_t *alength, const uint32_
    va_list     args;

    if ((array == NULL) || (alength == NULL)) {
        exit(0);
        exit(EXIT_FAILURE);
    }
    ptr              = array;
    remaining_length = *alength;
@@ -1350,17 +1351,17 @@ void ascii_hex_strings_to_uint8(uint8_t *array, uint32_t *alength, const uint32_
    for (i = 0; i < scount; i++) {
        if ((pos = va_arg(args, const char *)) == NULL) {
            va_end(args);
            exit(0);
            exit(EXIT_FAILURE);
        }
        str_length = (uint32_t)strlen(pos);
        if (str_length % 2) {
            va_end(args);
            exit(0);
            exit(EXIT_FAILURE);
        }
        *alength = *alength + (str_length / 2);
        if (remaining_length < str_length / 2) {
            va_end(args);
            exit(0);
            exit(EXIT_FAILURE);
        }
        for (j = 0; j < str_length / 2; j++) {
            sscanf(pos, "%2hhx", ptr++);
@@ -1383,7 +1384,7 @@ void message_formatting_function(uint8_t *array, uint32_t *alength, const uint32
    va_list     args;

    if ((array == NULL) || (alength == NULL)) {
        exit(0);
        exit(EXIT_FAILURE);
    }
    ptr              = array;
    remaining_length = *alength;
@@ -1392,16 +1393,16 @@ void message_formatting_function(uint8_t *array, uint32_t *alength, const uint32
    for (i = 0; i < scount; i++) {
        if ((pos = va_arg(args, const char *)) == NULL) {
            va_end(args);
            exit(0);
            exit(EXIT_FAILURE);
        }
        str_length = (uint32_t)strlen(pos);
        if (str_length % 2) {
            va_end(args);
            exit(0);
            exit(EXIT_FAILURE);
        }
        if (remaining_length < str_length / 2) {
            va_end(args);
            exit(0);
            exit(EXIT_FAILURE);
        }
        if (i != 0){
            length = htonl(str_length);
Loading