@@ -12,8 +12,7 @@ static wolfIP_esp_sa out_sa_list[WOLFIP_ESP_NUM_SA];
1212static uint16_t in_sa_num = WOLFIP_ESP_NUM_SA ;
1313static uint16_t out_sa_num = WOLFIP_ESP_NUM_SA ;
1414
15- int
16- wolfIP_esp_init (void )
15+ int wolfIP_esp_init (void )
1716{
1817 int err = 0 ;
1918
@@ -34,9 +33,15 @@ wolfIP_esp_init(void)
3433 return err ;
3534}
3635
37- int
38- wolfIP_esp_sa_new_aead (int in , uint8_t * spi , ip4 src , ip4 dst ,
39- uint8_t * enc_key , uint8_t enc_key_len )
36+ void wolfIP_esp_sa_del (void )
37+ {
38+ memset (in_sa_list , 0 , sizeof (in_sa_list ));
39+ memset (out_sa_list , 0 , sizeof (out_sa_list ));
40+ return ;
41+ }
42+
43+ int wolfIP_esp_sa_new_aead (int in , uint8_t * spi , ip4 src , ip4 dst ,
44+ uint8_t * enc_key , uint8_t enc_key_len )
4045{
4146 wolfIP_esp_sa * new_sa = NULL ;
4247 wolfIP_esp_sa * list = NULL ;
@@ -76,7 +81,8 @@ wolfIP_esp_sa_new_aead(int in, uint8_t * spi, ip4 src, ip4 dst,
7681 new_sa -> icv_len = ESP_GCM_RFC4106_ICV_LEN ;
7782
7883 /* Generate pre-iv for gcm. */
79- err = wc_RNG_GenerateBlock (& wc_rng , new_sa -> pre_iv , ESP_GCM_RFC4106_IV_LEN );
84+ err = wc_RNG_GenerateBlock (& wc_rng , new_sa -> pre_iv ,
85+ ESP_GCM_RFC4106_IV_LEN );
8086 if (err ) {
8187 printf ("error: wc_RNG_GenerateBlock: %d\n" , err );
8288 }
@@ -94,11 +100,10 @@ wolfIP_esp_sa_new_aead(int in, uint8_t * spi, ip4 src, ip4 dst,
94100 return err ;
95101}
96102
97- int
98- wolfIP_esp_sa_new_cbc_sha256 (int in , uint8_t * spi , ip4 src , ip4 dst ,
99- uint8_t * enc_key , uint8_t enc_key_len ,
100- uint8_t * auth_key , uint8_t auth_key_len ,
101- uint8_t icv_len )
103+ int wolfIP_esp_sa_new_cbc_sha256 (int in , uint8_t * spi , ip4 src , ip4 dst ,
104+ uint8_t * enc_key , uint8_t enc_key_len ,
105+ uint8_t * auth_key , uint8_t auth_key_len ,
106+ uint8_t icv_len )
102107{
103108 wolfIP_esp_sa * new_sa = NULL ;
104109 wolfIP_esp_sa * list = NULL ;
@@ -147,27 +152,6 @@ wolfIP_esp_sa_new_cbc_sha256(int in, uint8_t * spi, ip4 src, ip4 dst,
147152 return err ;
148153}
149154
150- #if 0
151- void
152- wolfIP_esp_load_sa_list (struct wolfIP_esp_sa * sa_list , uint16_t num , int in )
153- {
154- #ifdef WOLFIP_DEBUG_ESP
155- printf ("info: esp_load_sa_list: %p, %d, %d\n" , sa_list , num , in );
156- #endif /* WOLFIP_DEBUG_ESP */
157-
158- if (in == 1 ) {
159- in_sa_list = sa_list ;
160- in_sa_num = num ;
161- }
162- else {
163- out_sa_list = sa_list ;
164- out_sa_num = num ;
165- }
166-
167- return ;
168- }
169- #endif
170-
171155#ifdef WOLFIP_DEBUG_ESP
172156static void
173157esp_dump_data (const char * what , const uint8_t * data , size_t data_len )
@@ -1013,7 +997,8 @@ esp_transport_unwrap(struct wolfIP *s, struct wolfIP_ip_packet *ip,
1013997 }
1014998
1015999 if (err ) {
1016- printf ("error: esp_decrypt(%02x) returned: %d\n" , esp_sa -> enc , err );
1000+ printf ("error: esp_decrypt(%02x) returned: %d\n" , esp_sa -> enc ,
1001+ err );
10171002 return -1 ;
10181003 }
10191004
@@ -1074,6 +1059,7 @@ esp_transport_unwrap(struct wolfIP *s, struct wolfIP_ip_packet *ip,
10741059 *
10751060 * Returns 0 on success.
10761061 * Returns -1 on error.
1062+ * Returns 1 if no ipsec policy not found (send plaintext)
10771063 * */
10781064static int
10791065esp_transport_wrap (struct wolfIP_ip_packet * ip , uint16_t * ip_len )
@@ -1096,7 +1082,8 @@ esp_transport_wrap(struct wolfIP_ip_packet *ip, uint16_t * ip_len)
10961082 esp_sa = & out_sa_list [i ];
10971083 #ifdef WOLFIP_DEBUG_ESP
10981084 printf ("info: found out sa: 0x%02x%02x%02x%02x\n" ,
1099- esp_sa -> spi [0 ], esp_sa -> spi [1 ], esp_sa -> spi [2 ], esp_sa -> spi [3 ]);
1085+ esp_sa -> spi [0 ], esp_sa -> spi [1 ], esp_sa -> spi [2 ],
1086+ esp_sa -> spi [3 ]);
11001087 #endif /* WOLFIP_DEBUG_ESP */
11011088 break ;
11021089 }
@@ -1110,7 +1097,7 @@ esp_transport_wrap(struct wolfIP_ip_packet *ip, uint16_t * ip_len)
11101097 iptoa (ip -> dst , ip_str );
11111098 printf ("info: ip dst not found: %s\n" , ip_str );
11121099 #endif /* WOLFIP_DEBUG_ESP */
1113- return 0 ;
1100+ return 1 ;
11141101 }
11151102
11161103 iv_len = esp_iv_len_from_enc (esp_sa -> enc );
@@ -1211,7 +1198,8 @@ esp_transport_wrap(struct wolfIP_ip_packet *ip, uint16_t * ip_len)
12111198 }
12121199
12131200 if (err ) {
1214- printf ("error: esp_encrypt(%02x) returned: %d\n" , esp_sa -> enc , err );
1201+ printf ("error: esp_encrypt(%02x) returned: %d\n" , esp_sa -> enc ,
1202+ err );
12151203 return -1 ;
12161204 }
12171205
@@ -1263,7 +1251,8 @@ esp_transport_wrap(struct wolfIP_ip_packet *ip, uint16_t * ip_len)
12631251 * in the fifo circular buffer for each tcp packet, so we can expand in place.
12641252 * */
12651253static int
1266- esp_tcp_output (struct wolfIP_ll_dev * ll_dev , const struct wolfIP_ip_packet * ip ,
1254+ esp_tcp_output (struct wolfIP_ll_dev * ll_dev ,
1255+ const struct wolfIP_ip_packet * ip ,
12671256 uint16_t len )
12681257{
12691258 /**
@@ -1287,7 +1276,7 @@ esp_tcp_output(struct wolfIP_ll_dev * ll_dev, const struct wolfIP_ip_packet *ip,
12871276
12881277 if (esp_rc ) {
12891278 #ifdef WOLFIP_DEBUG_ESP
1290- printf ("error : esp_wrap returned: %d\n" , esp_rc );
1279+ printf ("info : esp_wrap returned: %d\n" , esp_rc );
12911280 #endif /* WOLFIP_DEBUG_ESP */
12921281 return esp_rc ;
12931282 }
0 commit comments