Skip to content

Commit 65d983f

Browse files
author
Mika Leppänen
committed
If mbedtls NIST AES KW is not enabled defined it as null algorithm
mbedtls NIST AES KW is not enabled as default, so if it is not defined in build, implemented it temporally as null encryption algrorithm. !!! This is to be removed after configurations are updated
1 parent 16dbe27 commit 65d983f

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

source/Service_Libs/nist_aes_kw/nist_aes_kw.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "mbedtls/nist_kw.h"
2424
#include "Service_Libs/nist_aes_kw/nist_aes_kw.h"
2525

26+
#ifdef HAVE_WS
27+
2628
#define TRACE_GROUP "naes"
2729

2830
int8_t nist_aes_key_wrap(uint8_t is_wrap, const uint8_t *key, int16_t key_bits, const uint8_t *input, size_t input_len, uint8_t *output, size_t *output_len)
@@ -93,5 +95,62 @@ int8_t nist_aes_key_wrap(uint8_t is_wrap, const uint8_t *key, int16_t key_bits,
9395

9496
error:
9597
mbedtls_nist_kw_free(&ctx);
98+
9699
return ret_val;
97100
}
101+
102+
#if !defined(MBEDTLS_NIST_KW_C)
103+
104+
// Temporal implementation until MBEDTLS_NIST_KW_C is enabled on all platforms
105+
106+
void mbedtls_nist_kw_init(mbedtls_nist_kw_context *ctx)
107+
{
108+
(void) ctx;
109+
}
110+
111+
int mbedtls_nist_kw_setkey( mbedtls_nist_kw_context *ctx,
112+
mbedtls_cipher_id_t cipher,
113+
const unsigned char *key,
114+
unsigned int keybits,
115+
const int is_wrap)
116+
{
117+
(void) ctx;
118+
(void) cipher;
119+
(void) key;
120+
(void) keybits;
121+
(void) is_wrap;
122+
return 0;
123+
}
124+
125+
int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode,
126+
const unsigned char *input, size_t in_len,
127+
unsigned char *output, size_t* out_len, size_t out_size)
128+
{
129+
(void) ctx;
130+
(void) mode;
131+
memset(output, 0, out_size);
132+
memcpy(output, input, in_len);
133+
*out_len = in_len + 8;
134+
return 0;
135+
}
136+
137+
int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode,
138+
const unsigned char *input, size_t in_len,
139+
unsigned char *output, size_t* out_len, size_t out_size)
140+
{
141+
(void) ctx;
142+
(void) mode;
143+
*out_len = in_len - 8;
144+
memset(output, 0, out_size);
145+
memcpy(output, input, *out_len);
146+
return 0;
147+
}
148+
149+
void mbedtls_nist_kw_free( mbedtls_nist_kw_context *ctx )
150+
{
151+
(void) ctx;
152+
}
153+
154+
#endif
155+
156+
#endif

0 commit comments

Comments
 (0)