Skip to content

Commit

Permalink
Merge #19278 #19290
Browse files Browse the repository at this point in the history
19278: gnrc_dhcpv6_client_simple_pd: select upstream based on type/index r=benpicco a=benpicco



19290: sys/crypto: make AES_KEY struct private & rename it r=benpicco a=benpicco



Co-authored-by: Benjamin Valentin <[email protected]>
Co-authored-by: Benjamin Valentin <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2023
3 parents 523a39a + 28289a1 + d6e2499 commit be29a00
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
24 changes: 16 additions & 8 deletions sys/crypto/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
* @}
*/

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -62,6 +60,16 @@
# define AES_KEY_SIZE(ctx) ctx->key_size
#endif

/**
* @brief AES key
* @see cipher_context_t
*/
typedef struct {
/** @cond INTERNAL */
uint32_t rd_key[4 * (AES_MAXNR + 1)];
int rounds;
/** @endcond */
} aes_key_t;
/**
* Interface to the aes cipher
*/
Expand Down Expand Up @@ -860,7 +868,7 @@ int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
* Expand the cipher key into the encryption key schedule.
*/
static int aes_set_encrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key)
aes_key_t *key)
{
u32 *rk;
int i = 0;
Expand Down Expand Up @@ -979,7 +987,7 @@ static int aes_set_encrypt_key(const unsigned char *userKey, const int bits,
* Expand the cipher key into the decryption key schedule.
*/
static int aes_set_decrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key)
aes_key_t *key)
{
u32 *rk;
int i, j;
Expand Down Expand Up @@ -1062,8 +1070,8 @@ int aes_encrypt(const cipher_context_t *context, const uint8_t *plainBlock,
{
/* setup AES_KEY */
int res;
AES_KEY aeskey;
const AES_KEY *key = &aeskey;
aes_key_t aeskey;
const aes_key_t *key = &aeskey;

res = aes_set_encrypt_key((unsigned char *)context->context,
AES_KEY_SIZE(context) * 8, &aeskey);
Expand Down Expand Up @@ -1331,8 +1339,8 @@ int aes_decrypt(const cipher_context_t *context, const uint8_t *cipherBlock,
{
/* setup AES_KEY */
int res;
AES_KEY aeskey;
const AES_KEY *key = &aeskey;
aes_key_t aeskey;
const aes_key_t *key = &aeskey;

res = aes_set_decrypt_key((unsigned char *)context->context,
AES_KEY_SIZE(context) * 8, &aeskey);
Expand Down
15 changes: 0 additions & 15 deletions sys/include/crypto/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
#ifndef CRYPTO_AES_H
#define CRYPTO_AES_H

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "crypto/ciphers.h"

Expand Down Expand Up @@ -64,17 +60,6 @@ typedef uint8_t u8;
#define AES_KEY_SIZE_256 32
/** @} */

/**
* @brief AES key
* @see cipher_context_t
*/
typedef struct aes_key_st {
/** @cond INTERNAL */
uint32_t rd_key[4 * (AES_MAXNR + 1)];
int rounds;
/** @endcond */
} AES_KEY;

/**
* @brief the cipher_context_t-struct adapted for AES
*/
Expand Down
19 changes: 19 additions & 0 deletions sys/include/net/gnrc/dhcpv6/client/simple_pd.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ extern "C" {
#define CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM (0)
#endif

/**
* @brief Interface type of the upstream interface
*
* See @ref netdev_type_t for possible values
*/
#ifndef CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE
#define CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE NETDEV_ANY
#endif

/**
* @brief Interface index of the upstream interface
*
* If there are multiple interfaces of the same type, set this to select
* which one to use for the upstream.
*/
#ifndef CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_IDX
#define CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_IDX (0)
#endif

/**
* @brief 6LoWPAN compression context lifetime for configured prefixes in
* minutes
Expand Down
13 changes: 13 additions & 0 deletions sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ static gnrc_netif_t *_find_upstream_netif(void)
if (CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM) {
return gnrc_netif_get_by_pid(CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM);
}

if (CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE != NETDEV_ANY) {
return gnrc_netif_get_by_type(CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE,
CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_IDX);
}

while ((netif = gnrc_netif_iter(netif))) {
if (!gnrc_netif_is_6lo(netif)) {
LOG_WARNING("DHCPv6: Selecting interface %d as upstream\n",
Expand Down Expand Up @@ -93,9 +99,16 @@ static void _configure_dhcpv6_client(void)
{
gnrc_netif_t *netif = NULL;
gnrc_netif_t *upstream = _find_upstream_netif();

if (upstream == NULL) {
LOG_ERROR("DHCPv6: No upstream interface found!\n");
return;
}

if (IS_ACTIVE(MODULE_DHCPV6_CLIENT_IA_NA)) {
upstream->ipv6.aac_mode |= GNRC_NETIF_AAC_DHCP;
}

while ((netif = gnrc_netif_iter(netif))) {
if (IS_USED(MODULE_GNRC_DHCPV6_CLIENT_6LBR)
&& !gnrc_netif_is_6lo(netif)) {
Expand Down
1 change: 1 addition & 0 deletions tests/sys_crypto/tests-crypto-aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* directory for more details.
*/

#include <string.h>
#include <limits.h>

#include "embUnit.h"
Expand Down

0 comments on commit be29a00

Please sign in to comment.