Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apps/crypto: support openssl wrappers by mbedtls #2784

Merged
merged 7 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions crypto/openssl_mbedtls_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ##############################################################################
# apps/crypto/openssl_mbedtls_wrapper/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_OPENSSL_MBEDTLS_WRAPPER)

set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include)

file(GLOB CSRCS ${CMAKE_CURRENT_LIST_DIR}/mbedtls/*.c)
target_sources(apps PRIVATE ${CSRCS})
endif()
9 changes: 9 additions & 0 deletions crypto/openssl_mbedtls_wrapper/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config OPENSSL_MBEDTLS_WRAPPER
depends on CRYPTO_MBEDTLS
bool "openssl mbedtls wrapper"
default n
25 changes: 25 additions & 0 deletions crypto/openssl_mbedtls_wrapper/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
############################################################################
# apps/crypto/openssl_mbedtls_wrapper/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_OPENSSL_MBEDTLS_WRAPPER),)
CONFIGURED_APPS += $(APPDIR)/crypto/openssl_mbedtls_wrapper
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/openssl_mbedtls_wrapper/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/openssl_mbedtls_wrapper/include
endif
23 changes: 23 additions & 0 deletions crypto/openssl_mbedtls_wrapper/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# apps/crypto/openssl_mbedtls_wrapper/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs
CSRCS += $(wildcard $(APPDIR)/crypto/openssl_mbedtls_wrapper/mbedtls/*.c)
include $(APPDIR)/Application.mk
80 changes: 80 additions & 0 deletions crypto/openssl_mbedtls_wrapper/include/openssl/aes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/****************************************************************************
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/aes.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
****************************************************************************/

#ifndef OPENSSL_MBEDTLS_WRAPPER_AES_H
#define OPENSSL_MBEDTLS_WRAPPER_AES_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <openssl/base.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define AES_ENCRYPT 1
#define AES_DECRYPT 0

#define AES_BLOCK_SIZE 16
#define AES_MAXNR 14

#ifdef __cplusplus
extern "C"
{
#endif

/****************************************************************************
* Public Types
****************************************************************************/

struct aes_key_st
{
uint32_t rd_key[4 * (AES_MAXNR + 1)];
unsigned rounds;
};

typedef struct aes_key_st AES_KEY;

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

int AES_set_encrypt_key(const uint8_t *key, unsigned bits,

Check failure on line 60 in crypto/openssl_mbedtls_wrapper/include/openssl/aes.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found
AES_KEY *aeskey);

void AES_encrypt(const uint8_t *in, uint8_t *out,

Check failure on line 63 in crypto/openssl_mbedtls_wrapper/include/openssl/aes.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found
const AES_KEY *key);

int AES_set_decrypt_key(const uint8_t *key, unsigned bits,

Check failure on line 66 in crypto/openssl_mbedtls_wrapper/include/openssl/aes.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found
AES_KEY *aeskey);

void AES_decrypt(const uint8_t *in, uint8_t *out,

Check failure on line 69 in crypto/openssl_mbedtls_wrapper/include/openssl/aes.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found
const AES_KEY *key);

void AES_cbc_encrypt(const uint8_t *in, uint8_t *out,

Check failure on line 72 in crypto/openssl_mbedtls_wrapper/include/openssl/aes.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found
size_t len, const AES_KEY *key,
uint8_t *ivec, const int enc);

#ifdef __cplusplus
}
#endif

#endif /* OPENSSL_MBEDTLS_WRAPPER_AES_H */
82 changes: 82 additions & 0 deletions crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/****************************************************************************
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
****************************************************************************/

#ifndef OPENSSL_MBEDTLS_WRAPPER_ASN1_H
#define OPENSSL_MBEDTLS_WRAPPER_ASN1_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <openssl/base.h>
#include <time.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define MBSTRING_FLAG 0x1000
#define MBSTRING_UTF8 (MBSTRING_FLAG)
#define MBSTRING_ASC (MBSTRING_FLAG | 1)

#define V_ASN1_NULL 5

#ifdef __cplusplus
extern "C"
{
#endif

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

void ASN1_BIT_STRING_free(ASN1_BIT_STRING *a);

Check failure on line 49 in crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

void ASN1_INTEGER_free(ASN1_INTEGER *a);

Check failure on line 51 in crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

void ASN1_OBJECT_free(ASN1_OBJECT *a);

Check failure on line 53 in crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a);

Check failure on line 55 in crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

void ASN1_TIME_free(ASN1_TIME *a);

Check failure on line 57 in crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

ASN1_BIT_STRING *ASN1_BIT_STRING_new(void);

int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *str, int n, int value);

ASN1_OCTET_STRING *ASN1_OCTET_STRING_new(void);

int i2d_ASN1_BIT_STRING(const ASN1_BIT_STRING *in, uint8_t **outp);

int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str,
const unsigned char *data, int len);

ASN1_INTEGER *ASN1_INTEGER_new(void);

ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);

ASN1_TIME *ASN1_TIME_new(void);

ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);

#ifdef __cplusplus
}
#endif

#endif /* OPENSSL_MBEDTLS_WRAPPER_ASN1_H */
81 changes: 81 additions & 0 deletions crypto/openssl_mbedtls_wrapper/include/openssl/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/****************************************************************************
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/base.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
****************************************************************************/

#ifndef OPENSSL_MBEDTLS_WRAPPER_BASE_H
#define OPENSSL_MBEDTLS_WRAPPER_BASE_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define ASN1_BIT_STRING ASN1_STRING

#ifdef __cplusplus
extern "C"
{
#endif

/****************************************************************************
* Public Types
****************************************************************************/

typedef struct EVP_CIPHER EVP_CIPHER;
typedef struct EVP_CIPHER_CTX EVP_CIPHER_CTX;
typedef struct ENGINE ENGINE;
typedef struct EVP_MD EVP_MD;
typedef struct EVP_MD_CTX EVP_MD_CTX;
typedef struct ASN1_BIT_STRING ASN1_BIT_STRING;
typedef struct ASN1_INTEGER ASN1_INTEGER;
typedef struct ASN1_OBJECT ASN1_OBJECT;
typedef struct ASN1_OCTET_STRING ASN1_OCTET_STRING;
typedef struct ASN1_TIME ASN1_TIME;
typedef struct BN_CTX BN_CTX;
typedef struct EC_GROUP EC_GROUP;
typedef struct EC_KEY EC_KEY;
typedef struct EC_POINT EC_POINT;
typedef struct evp_pkey_st EVP_PKEY;
typedef struct EVP_PKEY_CTX EVP_PKEY_CTX;
typedef struct PKCS8_PRIV_KEY_INFO PKCS8_PRIV_KEY_INFO;
typedef struct X509_ALGOR X509_ALGOR;
typedef struct X509_EXTENSION X509_EXTENSION;
typedef struct X509_NAME X509_NAME;
typedef struct BIGNUM BIGNUM;
typedef struct HMAC_CTX HMAC_CTX;
typedef struct rsa_meth_st RSA_METHOD;
typedef struct ecdsa_method_st ECDSA_METHOD;
typedef struct BN_GENCB BN_GENCB;
typedef struct sha256_state_st SHA256_CTX;
typedef struct sha_state_st SHA_CTX;
typedef struct cbb_st CBB;
typedef struct ecdsa_sig_st ECDSA_SIG;
typedef void RSA;

#ifdef __cplusplus
}
#endif

#endif /* OPENSSL_MBEDTLS_WRAPPER_BASE_H */
42 changes: 42 additions & 0 deletions crypto/openssl_mbedtls_wrapper/include/openssl/bio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************************
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/bio.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
****************************************************************************/

#ifndef OPENSSL_MBEDTLS_WRAPPER_BIO_H
#define OPENSSL_MBEDTLS_WRAPPER_BIO_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <openssl/base.h>

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

#ifdef __cplusplus
}
#endif

#endif /* OPENSSL_MBEDTLS_WRAPPER_BIO_H */
Loading
Loading