#include "../ssl/ssl_locl.h"
#include "testutil.h"
+#include "test_main.h"
#define IVLEN 12
#define KEYLEN 16
{
}
+int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
+ const EVP_MD **md, int *mac_pkey_type,
+ size_t *mac_secret_size, SSL_COMP **comp, int use_etm)
+
+{
+ 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,
const unsigned char *ref_secret,
const unsigned char *ref_key, const unsigned char *ref_iv)
{
- size_t hashsize = EVP_MD_size(ssl_handshake_md(s));
+ size_t hashsize;
unsigned char gensecret[EVP_MAX_MD_SIZE];
+ unsigned char hash[EVP_MAX_MD_SIZE];
unsigned char key[KEYLEN];
unsigned char iv[IVLEN];
+ const EVP_MD *md = ssl_handshake_md(s);
- if (!tls13_derive_secret(s, prk, label, labellen, gensecret)) {
+ if (!ssl_handshake_hash(s, hash, sizeof(hash), &hashsize)) {
+ fprintf(stderr, "Failed to get hash\n");
+ return 0;
+ }
+
+ if (!tls13_hkdf_expand(s, md, prk, label, labellen, hash, gensecret,
+ hashsize)) {
fprintf(stderr, "Secret generation failed\n");
return 0;
}
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;
}
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;
}
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;
}
return ret;
}
-int main(int argc, char *argv[])
+void register_tests()
{
- BIO *err = NULL;
- int testresult = 1;
-
- err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
-
- CRYPTO_set_mem_debug(1);
- CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
-
ADD_TEST(test_handshake_secrets);
-
- testresult = run_tests(argv[0]);
-
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- if (CRYPTO_mem_leaks(err) <= 0)
- testresult = 1;
-#endif
- BIO_free(err);
-
- if (!testresult)
- fprintf(stderr, "PASS\n");
-
- return testresult;
}