|
8 | 8 | #include "ZW_PRNG.h" |
9 | 9 | #include "ZIP_Router_logging.h" |
10 | 10 | #include "zip_router_config.h" |
| 11 | +#include "random.h" |
11 | 12 | #define NONCE_OPT 0 |
12 | 13 |
|
13 | 14 | /**/ |
|
23 | 24 | #define NONCE_BLACKLIST_SIZE 10 |
24 | 25 | #define RECEIVERS_NONCE_SIZE 8 /* The size of the nonce field in a Nonce Report */ |
25 | 26 |
|
| 27 | +#define S0_KEY_SIZE 16 /* The S0 Key Size */ |
| 28 | + |
26 | 29 | typedef enum { |
27 | 30 | NONCE_GET, |
28 | 31 | NONCE_GET_SENT, |
@@ -59,7 +62,7 @@ typedef struct _AUTHDATA_ { |
59 | 62 | extern u8_t send_data(ts_param_t* p, const u8_t* data, u16_t len,ZW_SendDataAppl_Callback_t cb,void* user); |
60 | 63 |
|
61 | 64 | static sec_tx_session_t tx_sessions[NUM_TX_SESSIONS]; |
62 | | -uint8_t networkKey[16]; /* The master key */ |
| 65 | +uint8_t networkKey[S0_KEY_SIZE] = {0}; /* The master key */ |
63 | 66 |
|
64 | 67 |
|
65 | 68 | /* Nonce blacklist type*/ |
@@ -885,10 +888,24 @@ uint8_t sec0_decrypt_message(uint8_t snode, uint8_t dnode, uint8_t* enc_data, ui |
885 | 888 | } |
886 | 889 |
|
887 | 890 |
|
888 | | -void sec0_reset_netkey() { |
| 891 | +void sec0_reset_netkey(void) { |
| 892 | + uint8_t n=0; |
| 893 | + bool bSuccess=false; |
| 894 | + |
889 | 895 | LOG_PRINTF("Reinitializing S0 network key (S2 keys are unchanged)\n"); |
890 | | - aes_random8( &networkKey[0] ); |
891 | | - aes_random8( &networkKey[8] ); |
| 896 | + do { |
| 897 | + bSuccess = dev_urandom(sizeof(networkKey),networkKey); |
| 898 | + if (bSuccess) { |
| 899 | + break; |
| 900 | + } |
| 901 | + } while (n++ <= 10); |
| 902 | + |
| 903 | + if(bSuccess) { |
| 904 | + nvm_config_set(security_netkey,networkKey); |
| 905 | + } |
| 906 | + else { |
| 907 | + ERR_PRINTF("Failed to generate random S0 key. Security compromised!\n"); |
| 908 | + } |
892 | 909 |
|
893 | | - nvm_config_set(security_netkey,networkKey); |
| 910 | + ASSERT(bSuccess); |
894 | 911 | } |
0 commit comments