Skip to content

Commit 5189582

Browse files
committed
fixup! Add support for integrity-only cipher suites for TLS v1.3
1 parent 54b164b commit 5189582

File tree

6 files changed

+31
-32
lines changed

6 files changed

+31
-32
lines changed

doc/man1/openssl-ciphers.pod.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ Note: the CBC modes mentioned in this RFC are not supported.
743743
TLS_SHA256_SHA256 TLS_SHA256_SHA256
744744
TLS_SHA384_SHA384 TLS_SHA384_SHA384
745745

746-
Note: these ciphers are HMAC based and do not provide any confidentiality
746+
Note: these ciphers are purely HMAC based and do not provide any confidentiality
747747
and thus are disabled by default.
748748
These ciphers are available at security level 0.
749749

doc/man3/SSL_CTX_set_cipher_list.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ ciphersuite names in order of preference. Valid TLSv1.3 ciphersuite names are:
5050

5151
=item TLS_AES_128_CCM_8_SHA256
5252

53-
=item TLS_SHA384_SHA384
53+
=item TLS_SHA384_SHA384 - integrity-only!
5454

55-
=item TLS_SHA256_SHA256
55+
=item TLS_SHA256_SHA256 - integrity-only!
5656

5757
=back
5858

ssl/record/methods/recmethod_local.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ struct ossl_record_layer_st
295295
/* cryptographic state */
296296
EVP_CIPHER_CTX *enc_ctx;
297297

298-
/* TLSv1.3 MAC ctx, only used with Integrity-Only cipher*/
298+
/* TLSv1.3 MAC ctx, only used with integrity-only cipher */
299299
EVP_MAC_CTX *mac_ctx;
300300

301301
/* Explicit IV length */
@@ -336,9 +336,8 @@ struct ossl_record_layer_st
336336
int tlstree;
337337

338338
/* TLSv1.3 fields */
339-
/* static IV */
340-
unsigned char *iv;
341-
unsigned char *nonce;
339+
unsigned char *iv; /* static IV */
340+
unsigned char *nonce; /* part of static IV followed by sequence number */
342341
int allow_plain_alerts;
343342

344343
/* TLS "any" fields */

ssl/record/methods/tls13_meth.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int tls13_set_crypto_state(OSSL_RECORD_LAYER *rl, int level,
3636
return OSSL_RECORD_RETURN_FATAL;
3737
}
3838

39-
rl->nonce = OPENSSL_zalloc(ivlen);
39+
rl->nonce = OPENSSL_malloc(ivlen);
4040
if (rl->nonce == NULL) {
4141
ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);
4242
return OSSL_RECORD_RETURN_FATAL;
@@ -89,10 +89,10 @@ static int tls13_cipher(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *recs,
8989
size_t n_recs, int sending, SSL_MAC_BUF *mac,
9090
size_t macsize)
9191
{
92-
EVP_CIPHER_CTX *ctx;
92+
EVP_CIPHER_CTX *enc_ctx;
9393
unsigned char recheader[SSL3_RT_HEADER_LENGTH];
9494
unsigned char tag[EVP_MAX_MD_SIZE];
95-
size_t ivlen, offset, loop, hdrlen, taglen;
95+
size_t nonce_len, offset, loop, hdrlen, taglen;
9696
unsigned char *staticiv;
9797
unsigned char *nonce;
9898
unsigned char *seq = rl->sequence;
@@ -109,11 +109,11 @@ static int tls13_cipher(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *recs,
109109
return 0;
110110
}
111111

112-
ctx = rl->enc_ctx;
112+
enc_ctx = rl->enc_ctx; /* enc_ctx is ignored when rl->mac_ctx != NULL */
113113
staticiv = rl->iv;
114114
nonce = rl->nonce;
115115

116-
if (ctx == NULL && rl->mac_ctx == NULL) {
116+
if (enc_ctx == NULL && rl->mac_ctx == NULL) {
117117
RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
118118
return 0;
119119
}
@@ -130,11 +130,11 @@ static int tls13_cipher(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *recs,
130130
return 1;
131131
}
132132

133-
/* For Integrity Only, ivlen is same as MAC size */
133+
/* For integrity-only ciphers, nonce_len is same as MAC size */
134134
if (rl->mac_ctx != NULL)
135-
ivlen = EVP_MAC_CTX_get_mac_size(rl->mac_ctx);
135+
nonce_len = EVP_MAC_CTX_get_mac_size(rl->mac_ctx);
136136
else
137-
ivlen = EVP_CIPHER_CTX_get_iv_length(ctx);
137+
nonce_len = EVP_CIPHER_CTX_get_iv_length(enc_ctx);
138138

139139
if (!sending) {
140140
/*
@@ -146,13 +146,13 @@ static int tls13_cipher(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *recs,
146146
rec->length -= rl->taglen;
147147
}
148148

149-
/* Set up IV */
150-
if (ivlen < SEQ_NUM_SIZE) {
149+
/* Set up nonce: part of static IV followed by sequence number */
150+
if (nonce_len < SEQ_NUM_SIZE) {
151151
/* Should not happen */
152152
RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
153153
return 0;
154154
}
155-
offset = ivlen - SEQ_NUM_SIZE;
155+
offset = nonce_len - SEQ_NUM_SIZE;
156156
memcpy(nonce, staticiv, offset);
157157
for (loop = 0; loop < SEQ_NUM_SIZE; loop++)
158158
nonce[offset + loop] = staticiv[offset + loop] ^ seq[loop];
@@ -179,7 +179,7 @@ static int tls13_cipher(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *recs,
179179
int ret = 0;
180180

181181
if ((mac_ctx = EVP_MAC_CTX_dup(rl->mac_ctx)) == NULL
182-
|| !EVP_MAC_update(mac_ctx, nonce, ivlen)
182+
|| !EVP_MAC_update(mac_ctx, nonce, nonce_len)
183183
|| !EVP_MAC_update(mac_ctx, recheader, sizeof(recheader))
184184
|| !EVP_MAC_update(mac_ctx, rec->input, rec->length)
185185
|| !EVP_MAC_final(mac_ctx, tag, &taglen, rl->taglen)) {
@@ -200,15 +200,15 @@ static int tls13_cipher(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *recs,
200200
return ret;
201201
}
202202

203-
cipher = EVP_CIPHER_CTX_get0_cipher(ctx);
203+
cipher = EVP_CIPHER_CTX_get0_cipher(enc_ctx);
204204
if (cipher == NULL) {
205205
RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
206206
return 0;
207207
}
208208
mode = EVP_CIPHER_get_mode(cipher);
209209

210-
if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, nonce, sending) <= 0
211-
|| (!sending && EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
210+
if (EVP_CipherInit_ex(enc_ctx, NULL, NULL, NULL, nonce, sending) <= 0
211+
|| (!sending && EVP_CIPHER_CTX_ctrl(enc_ctx, EVP_CTRL_AEAD_SET_TAG,
212212
rl->taglen,
213213
rec->data + rec->length) <= 0)) {
214214
RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
@@ -220,19 +220,19 @@ static int tls13_cipher(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *recs,
220220
* any AAD.
221221
*/
222222
if ((mode == EVP_CIPH_CCM_MODE
223-
&& EVP_CipherUpdate(ctx, NULL, &lenu, NULL,
223+
&& EVP_CipherUpdate(enc_ctx, NULL, &lenu, NULL,
224224
(unsigned int)rec->length) <= 0)
225-
|| EVP_CipherUpdate(ctx, NULL, &lenu, recheader,
225+
|| EVP_CipherUpdate(enc_ctx, NULL, &lenu, recheader,
226226
sizeof(recheader)) <= 0
227-
|| EVP_CipherUpdate(ctx, rec->data, &lenu, rec->input,
227+
|| EVP_CipherUpdate(enc_ctx, rec->data, &lenu, rec->input,
228228
(unsigned int)rec->length) <= 0
229-
|| EVP_CipherFinal_ex(ctx, rec->data + lenu, &lenf) <= 0
229+
|| EVP_CipherFinal_ex(enc_ctx, rec->data + lenu, &lenf) <= 0
230230
|| (size_t)(lenu + lenf) != rec->length) {
231231
return 0;
232232
}
233233
if (sending) {
234234
/* Add the tag */
235-
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, rl->taglen,
235+
if (EVP_CIPHER_CTX_ctrl(enc_ctx, EVP_CTRL_AEAD_GET_TAG, rl->taglen,
236236
rec->data + rec->length) <= 0) {
237237
RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
238238
return 0;

ssl/tls13_enc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ int tls13_change_cipher_state(SSL_CONNECTION *s, int which)
487487

488488
if (((which & SSL3_CC_CLIENT) && (which & SSL3_CC_WRITE))
489489
|| ((which & SSL3_CC_SERVER) && (which & SSL3_CC_READ))) {
490-
if (which & SSL3_CC_EARLY) {
490+
if ((which & SSL3_CC_EARLY) != 0) {
491491
EVP_MD_CTX *mdctx = NULL;
492492
long handlen;
493493
void *hdata;
@@ -635,7 +635,7 @@ int tls13_change_cipher_state(SSL_CONNECTION *s, int which)
635635
}
636636
}
637637

638-
if (!(which & SSL3_CC_EARLY)) {
638+
if ((which & SSL3_CC_EARLY) == 0) {
639639
md = ssl_handshake_md(s);
640640
cipher = s->s3.tmp.new_sym_enc;
641641
mac_md = s->s3.tmp.new_hash;

test/sslapitest.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,7 +3942,7 @@ static int early_data_skip_helper(int testtype, int cipher, int idx)
39423942
unsigned char buf[20];
39433943
size_t readbytes, written;
39443944

3945-
if (is_fips && cipher >= 4 )
3945+
if (is_fips && cipher >= 4)
39463946
return 1;
39473947

39483948
if (ciphersuites[cipher] == NULL)
@@ -4483,8 +4483,8 @@ static int test_early_data_psk_with_all_ciphers(int idx)
44834483
if (cipher_str[idx] == NULL)
44844484
return 1;
44854485
/*
4486-
* Skip ChaCha20Poly1305 & TLS_SHA{256,384}_SHA{256,384} cipher as
4487-
* currently FIPS module does not support it.
4486+
* Skip ChaCha20Poly1305 and TLS_SHA{256,384}_SHA{256,384} ciphers
4487+
* as currently FIPS module does not support them.
44884488
*/
44894489
if ((idx == 2 || idx == 5 || idx == 6) && is_fips == 1)
44904490
return 1;

0 commit comments

Comments
 (0)