@@ -53,9 +53,9 @@ int ngtcp2_crypto_hkdf_expand_label(uint8_t *dest, size_t destlen,
5353
5454 * p ++ = (uint8_t )(destlen / 256 );
5555 * p ++ = (uint8_t )(destlen % 256 );
56- * p ++ = (uint8_t )(sizeof (LABEL ) - 1 + labellen );
57- memcpy (p , LABEL , sizeof (LABEL ) - 1 );
58- p += sizeof (LABEL ) - 1 ;
56+ * p ++ = (uint8_t )(ngtcp2_strlen_lit (LABEL ) + labellen );
57+ memcpy (p , LABEL , ngtcp2_strlen_lit (LABEL ));
58+ p += ngtcp2_strlen_lit (LABEL );
5959 memcpy (p , label , labellen );
6060 p += labellen ;
6161 * p ++ = 0 ;
@@ -88,11 +88,11 @@ int ngtcp2_crypto_derive_initial_secrets(uint8_t *rx_secret, uint8_t *tx_secret,
8888 case NGTCP2_PROTO_VER_V1 :
8989 default :
9090 salt = (const uint8_t * )NGTCP2_INITIAL_SALT_V1 ;
91- saltlen = sizeof (NGTCP2_INITIAL_SALT_V1 ) - 1 ;
91+ saltlen = ngtcp2_strlen_lit (NGTCP2_INITIAL_SALT_V1 );
9292 break ;
9393 case NGTCP2_PROTO_VER_V2 :
9494 salt = (const uint8_t * )NGTCP2_INITIAL_SALT_V2 ;
95- saltlen = sizeof (NGTCP2_INITIAL_SALT_V2 ) - 1 ;
95+ saltlen = ngtcp2_strlen_lit (NGTCP2_INITIAL_SALT_V2 );
9696 break ;
9797 }
9898
@@ -111,10 +111,12 @@ int ngtcp2_crypto_derive_initial_secrets(uint8_t *rx_secret, uint8_t *tx_secret,
111111
112112 if (ngtcp2_crypto_hkdf_expand_label (
113113 client_secret , NGTCP2_CRYPTO_INITIAL_SECRETLEN , & ctx .md , initial_secret ,
114- NGTCP2_CRYPTO_INITIAL_SECRETLEN , CLABEL , sizeof (CLABEL ) - 1 ) != 0 ||
114+ NGTCP2_CRYPTO_INITIAL_SECRETLEN , CLABEL ,
115+ ngtcp2_strlen_lit (CLABEL )) != 0 ||
115116 ngtcp2_crypto_hkdf_expand_label (
116117 server_secret , NGTCP2_CRYPTO_INITIAL_SECRETLEN , & ctx .md , initial_secret ,
117- NGTCP2_CRYPTO_INITIAL_SECRETLEN , SLABEL , sizeof (SLABEL ) - 1 ) != 0 ) {
118+ NGTCP2_CRYPTO_INITIAL_SECRETLEN , SLABEL ,
119+ ngtcp2_strlen_lit (SLABEL )) != 0 ) {
118120 return -1 ;
119121 }
120122
@@ -148,19 +150,19 @@ int ngtcp2_crypto_derive_packet_protection_key(
148150 switch (version ) {
149151 case NGTCP2_PROTO_VER_V2 :
150152 key_label = KEY_LABEL_V2 ;
151- key_labellen = sizeof (KEY_LABEL_V2 ) - 1 ;
153+ key_labellen = ngtcp2_strlen_lit (KEY_LABEL_V2 );
152154 iv_label = IV_LABEL_V2 ;
153- iv_labellen = sizeof (IV_LABEL_V2 ) - 1 ;
155+ iv_labellen = ngtcp2_strlen_lit (IV_LABEL_V2 );
154156 hp_key_label = HP_KEY_LABEL_V2 ;
155- hp_key_labellen = sizeof (HP_KEY_LABEL_V2 ) - 1 ;
157+ hp_key_labellen = ngtcp2_strlen_lit (HP_KEY_LABEL_V2 );
156158 break ;
157159 default :
158160 key_label = KEY_LABEL_V1 ;
159- key_labellen = sizeof (KEY_LABEL_V1 ) - 1 ;
161+ key_labellen = ngtcp2_strlen_lit (KEY_LABEL_V1 );
160162 iv_label = IV_LABEL_V1 ;
161- iv_labellen = sizeof (IV_LABEL_V1 ) - 1 ;
163+ iv_labellen = ngtcp2_strlen_lit (IV_LABEL_V1 );
162164 hp_key_label = HP_KEY_LABEL_V1 ;
163- hp_key_labellen = sizeof (HP_KEY_LABEL_V1 ) - 1 ;
165+ hp_key_labellen = ngtcp2_strlen_lit (HP_KEY_LABEL_V1 );
164166 }
165167
166168 if (ngtcp2_crypto_hkdf_expand_label (key , keylen , md , secret , secretlen ,
@@ -194,11 +196,11 @@ int ngtcp2_crypto_update_traffic_secret(uint8_t *dest, uint32_t version,
194196 switch (version ) {
195197 case NGTCP2_PROTO_VER_V2 :
196198 label = LABEL_V2 ;
197- labellen = sizeof (LABEL_V2 ) - 1 ;
199+ labellen = ngtcp2_strlen_lit (LABEL_V2 );
198200 break ;
199201 default :
200202 label = LABEL ;
201- labellen = sizeof (LABEL ) - 1 ;
203+ labellen = ngtcp2_strlen_lit (LABEL );
202204 }
203205
204206 if (ngtcp2_crypto_hkdf_expand_label (dest , secretlen , md , secret , secretlen ,
@@ -592,11 +594,11 @@ int ngtcp2_crypto_derive_and_install_initial_key(
592594 case NGTCP2_PROTO_VER_V1 :
593595 default :
594596 retry_key = (const uint8_t * )NGTCP2_RETRY_KEY_V1 ;
595- retry_noncelen = sizeof (NGTCP2_RETRY_NONCE_V1 ) - 1 ;
597+ retry_noncelen = ngtcp2_strlen_lit (NGTCP2_RETRY_NONCE_V1 );
596598 break ;
597599 case NGTCP2_PROTO_VER_V2 :
598600 retry_key = (const uint8_t * )NGTCP2_RETRY_KEY_V2 ;
599- retry_noncelen = sizeof (NGTCP2_RETRY_NONCE_V2 ) - 1 ;
601+ retry_noncelen = ngtcp2_strlen_lit (NGTCP2_RETRY_NONCE_V2 );
600602 break ;
601603 }
602604
@@ -845,7 +847,7 @@ int ngtcp2_crypto_generate_stateless_reset_token(uint8_t *token,
845847 if (ngtcp2_crypto_hkdf (token , NGTCP2_STATELESS_RESET_TOKENLEN ,
846848 ngtcp2_crypto_md_sha256 (& md ), secret , secretlen ,
847849 cid -> data , cid -> datalen , info ,
848- sizeof (info ) - 1 ) != 0 ) {
850+ ngtcp2_strlen_lit (info )) != 0 ) {
849851 return -1 ;
850852 }
851853
@@ -865,8 +867,8 @@ static int crypto_derive_token_key(uint8_t *key, size_t keylen, uint8_t *iv,
865867 uint8_t * p ;
866868
867869 assert (ngtcp2_crypto_md_hashlen (md ) == sizeof (intsecret ));
868- assert (info_prefixlen + sizeof (key_info_suffix ) - 1 <= sizeof (info ));
869- assert (info_prefixlen + sizeof (iv_info_suffix ) - 1 <= sizeof (info ));
870+ assert (info_prefixlen + ngtcp2_strlen_lit (key_info_suffix ) <= sizeof (info ));
871+ assert (info_prefixlen + ngtcp2_strlen_lit (iv_info_suffix ) <= sizeof (info ));
870872
871873 if (ngtcp2_crypto_hkdf_extract (intsecret , md , secret , secretlen , salt ,
872874 saltlen ) != 0 ) {
@@ -876,8 +878,8 @@ static int crypto_derive_token_key(uint8_t *key, size_t keylen, uint8_t *iv,
876878 memcpy (info , info_prefix , info_prefixlen );
877879 p = info + info_prefixlen ;
878880
879- memcpy (p , key_info_suffix , sizeof (key_info_suffix ) - 1 );
880- p += sizeof (key_info_suffix ) - 1 ;
881+ memcpy (p , key_info_suffix , ngtcp2_strlen_lit (key_info_suffix ));
882+ p += ngtcp2_strlen_lit (key_info_suffix );
881883
882884 if (ngtcp2_crypto_hkdf_expand (key , keylen , md , intsecret , sizeof (intsecret ),
883885 info , (size_t )(p - info )) != 0 ) {
@@ -886,8 +888,8 @@ static int crypto_derive_token_key(uint8_t *key, size_t keylen, uint8_t *iv,
886888
887889 p = info + info_prefixlen ;
888890
889- memcpy (p , iv_info_suffix , sizeof (iv_info_suffix ) - 1 );
890- p += sizeof (iv_info_suffix ) - 1 ;
891+ memcpy (p , iv_info_suffix , ngtcp2_strlen_lit (iv_info_suffix ));
892+ p += ngtcp2_strlen_lit (iv_info_suffix );
891893
892894 if (ngtcp2_crypto_hkdf_expand (iv , ivlen , md , intsecret , sizeof (intsecret ),
893895 info , (size_t )(p - info )) != 0 ) {
@@ -963,10 +965,10 @@ ngtcp2_ssize ngtcp2_crypto_generate_retry_token(
963965 assert (sizeof (key ) == keylen );
964966 assert (sizeof (iv ) == ivlen );
965967
966- if (crypto_derive_token_key (key , keylen , iv , ivlen , & md , secret , secretlen ,
967- rand_data , sizeof ( rand_data ) ,
968- retry_token_info_prefix ,
969- sizeof (retry_token_info_prefix ) - 1 ) != 0 ) {
968+ if (crypto_derive_token_key (
969+ key , keylen , iv , ivlen , & md , secret , secretlen , rand_data ,
970+ sizeof ( rand_data ), retry_token_info_prefix ,
971+ ngtcp2_strlen_lit (retry_token_info_prefix )) != 0 ) {
970972 return -1 ;
971973 }
972974
@@ -1040,10 +1042,10 @@ int ngtcp2_crypto_verify_retry_token(
10401042 assert (sizeof (key ) == keylen );
10411043 assert (sizeof (iv ) == ivlen );
10421044
1043- if (crypto_derive_token_key (key , keylen , iv , ivlen , & md , secret , secretlen ,
1044- rand_data , NGTCP2_CRYPTO_TOKEN_RAND_DATALEN ,
1045- retry_token_info_prefix ,
1046- sizeof (retry_token_info_prefix ) - 1 ) != 0 ) {
1045+ if (crypto_derive_token_key (
1046+ key , keylen , iv , ivlen , & md , secret , secretlen , rand_data ,
1047+ NGTCP2_CRYPTO_TOKEN_RAND_DATALEN , retry_token_info_prefix ,
1048+ ngtcp2_strlen_lit (retry_token_info_prefix )) != 0 ) {
10471049 return -1 ;
10481050 }
10491051
@@ -1143,10 +1145,10 @@ ngtcp2_ssize ngtcp2_crypto_generate_retry_token2(
11431145 assert (sizeof (key ) == keylen );
11441146 assert (sizeof (iv ) == ivlen );
11451147
1146- if (crypto_derive_token_key (key , keylen , iv , ivlen , & md , secret , secretlen ,
1147- rand_data , sizeof ( rand_data ) ,
1148- retry_token_info_prefix2 ,
1149- sizeof (retry_token_info_prefix2 ) - 1 ) != 0 ) {
1148+ if (crypto_derive_token_key (
1149+ key , keylen , iv , ivlen , & md , secret , secretlen , rand_data ,
1150+ sizeof ( rand_data ), retry_token_info_prefix2 ,
1151+ ngtcp2_strlen_lit (retry_token_info_prefix2 )) != 0 ) {
11501152 return -1 ;
11511153 }
11521154
@@ -1221,10 +1223,10 @@ int ngtcp2_crypto_verify_retry_token2(
12211223 assert (sizeof (key ) == keylen );
12221224 assert (sizeof (iv ) == ivlen );
12231225
1224- if (crypto_derive_token_key (key , keylen , iv , ivlen , & md , secret , secretlen ,
1225- rand_data , NGTCP2_CRYPTO_TOKEN_RAND_DATALEN ,
1226- retry_token_info_prefix2 ,
1227- sizeof (retry_token_info_prefix2 ) - 1 ) != 0 ) {
1226+ if (crypto_derive_token_key (
1227+ key , keylen , iv , ivlen , & md , secret , secretlen , rand_data ,
1228+ NGTCP2_CRYPTO_TOKEN_RAND_DATALEN , retry_token_info_prefix2 ,
1229+ ngtcp2_strlen_lit (retry_token_info_prefix2 )) != 0 ) {
12281230 return NGTCP2_CRYPTO_ERR_INTERNAL ;
12291231 }
12301232
@@ -1366,10 +1368,10 @@ static ngtcp2_ssize crypto_generate_regular_token(
13661368 assert (sizeof (key ) == keylen );
13671369 assert (sizeof (iv ) == ivlen );
13681370
1369- if (crypto_derive_token_key (key , keylen , iv , ivlen , & md , secret , secretlen ,
1370- rand_data , sizeof ( rand_data ) ,
1371- regular_token_info_prefix ,
1372- sizeof (regular_token_info_prefix ) - 1 ) != 0 ) {
1371+ if (crypto_derive_token_key (
1372+ key , keylen , iv , ivlen , & md , secret , secretlen , rand_data ,
1373+ sizeof ( rand_data ), regular_token_info_prefix ,
1374+ ngtcp2_strlen_lit (regular_token_info_prefix )) != 0 ) {
13731375 return -1 ;
13741376 }
13751377
@@ -1442,10 +1444,10 @@ static ngtcp2_ssize crypto_verify_regular_token(
14421444 assert (sizeof (key ) == keylen );
14431445 assert (sizeof (iv ) == ivlen );
14441446
1445- if (crypto_derive_token_key (key , keylen , iv , ivlen , & md , secret , secretlen ,
1446- rand_data , NGTCP2_CRYPTO_TOKEN_RAND_DATALEN ,
1447- regular_token_info_prefix ,
1448- sizeof (regular_token_info_prefix ) - 1 ) != 0 ) {
1447+ if (crypto_derive_token_key (
1448+ key , keylen , iv , ivlen , & md , secret , secretlen , rand_data ,
1449+ NGTCP2_CRYPTO_TOKEN_RAND_DATALEN , regular_token_info_prefix ,
1450+ ngtcp2_strlen_lit (regular_token_info_prefix )) != 0 ) {
14491451 return NGTCP2_CRYPTO_ERR_INTERNAL ;
14501452 }
14511453
@@ -1601,11 +1603,11 @@ ngtcp2_ssize ngtcp2_crypto_write_retry(uint8_t *dest, size_t destlen,
16011603 case NGTCP2_PROTO_VER_V1 :
16021604 default :
16031605 key = (const uint8_t * )NGTCP2_RETRY_KEY_V1 ;
1604- noncelen = sizeof (NGTCP2_RETRY_NONCE_V1 ) - 1 ;
1606+ noncelen = ngtcp2_strlen_lit (NGTCP2_RETRY_NONCE_V1 );
16051607 break ;
16061608 case NGTCP2_PROTO_VER_V2 :
16071609 key = (const uint8_t * )NGTCP2_RETRY_KEY_V2 ;
1608- noncelen = sizeof (NGTCP2_RETRY_NONCE_V2 ) - 1 ;
1610+ noncelen = ngtcp2_strlen_lit (NGTCP2_RETRY_NONCE_V2 );
16091611 break ;
16101612 }
16111613
0 commit comments