Implement the early data changes required in tls13_change_cipher_state()
[openssl.git] / test / tls13secretstest.c
index 93b6e442578ae46ad4e1cbb701f726f33f758b62..55424b1093b2240dff0aa0522bed47206dbaae0e 100644 (file)
@@ -179,6 +179,24 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
     return 0;
 }
 
+int tls1_alert_code(int code)
+{
+    return code;
+}
+
+int ssl_log_secret(SSL *ssl,
+                   const char *label,
+                   const uint8_t *secret,
+                   size_t secret_len)
+{
+    return 1;
+}
+
+const EVP_MD *ssl_md(int idx)
+{
+    return EVP_sha256();
+}
+
 /* End of mocked out code */
 
 static int test_secret(SSL *s, unsigned char *prk,
@@ -191,13 +209,14 @@ static int test_secret(SSL *s, unsigned char *prk,
     unsigned char hash[EVP_MAX_MD_SIZE];
     unsigned char key[KEYLEN];
     unsigned char iv[IVLEN];
+    const EVP_MD *md = ssl_handshake_md(s);
 
     if (!ssl_handshake_hash(s, hash, sizeof(hash), &hashsize)) {
         fprintf(stderr, "Failed to get hash\n");
         return 0;
     }
 
-    if (!tls13_hkdf_expand(s, prk, label, labellen, hash, gensecret,
+    if (!tls13_hkdf_expand(s, md, prk, label, labellen, hash, gensecret,
                            hashsize)) {
         fprintf(stderr, "Secret generation failed\n");
         return 0;
@@ -208,7 +227,7 @@ static int test_secret(SSL *s, unsigned char *prk,
         return 0;
     }
 
-    if (!tls13_derive_key(s, gensecret, key, KEYLEN)) {
+    if (!tls13_derive_key(s, md, gensecret, key, KEYLEN)) {
         fprintf(stderr, "Key generation failed\n");
         return 0;
     }
@@ -218,7 +237,7 @@ static int test_secret(SSL *s, unsigned char *prk,
         return 0;
     }
 
-    if (!tls13_derive_iv(s, gensecret, iv, IVLEN)) {
+    if (!tls13_derive_iv(s, md, gensecret, iv, IVLEN)) {
         fprintf(stderr, "IV generation failed\n");
         return 0;
     }
@@ -248,7 +267,12 @@ static int test_handshake_secrets(void)
     if (s == NULL)
         goto err;
 
-    if (!tls13_generate_early_secret(s, NULL, 0)) {
+    s->session = SSL_SESSION_new();
+    if (s->session == NULL)
+        goto err;
+
+    if (!tls13_generate_secret(s, ssl_handshake_md(s), NULL, NULL, 0,
+                               (unsigned char *)&s->early_secret)) {
         fprintf(stderr, "Early secret generation failed\n");
         goto err;
     }