11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 51cb0ef41Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at 71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html 81cb0ef41Sopenharmony_ci */ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci/* 111cb0ef41Sopenharmony_ci * SHA-1 low level APIs are deprecated for public use, but still ok for 121cb0ef41Sopenharmony_ci * internal use. 131cb0ef41Sopenharmony_ci */ 141cb0ef41Sopenharmony_ci#include "internal/deprecated.h" 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci#include <openssl/crypto.h> 171cb0ef41Sopenharmony_ci#include <openssl/opensslconf.h> 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci#include <openssl/opensslv.h> 201cb0ef41Sopenharmony_ci#include <openssl/evp.h> 211cb0ef41Sopenharmony_ci#include <openssl/sha.h> 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci/* The implementation is in ../md32_common.h */ 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci#include "sha_local.h" 261cb0ef41Sopenharmony_ci#include "crypto/sha.h" 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciint ossl_sha1_ctrl(SHA_CTX *sha1, int cmd, int mslen, void *ms) 291cb0ef41Sopenharmony_ci{ 301cb0ef41Sopenharmony_ci unsigned char padtmp[40]; 311cb0ef41Sopenharmony_ci unsigned char sha1tmp[SHA_DIGEST_LENGTH]; 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci if (cmd != EVP_CTRL_SSL3_MASTER_SECRET) 341cb0ef41Sopenharmony_ci return -2; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci if (sha1 == NULL) 371cb0ef41Sopenharmony_ci return 0; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci /* SSLv3 client auth handling: see RFC-6101 5.6.8 */ 401cb0ef41Sopenharmony_ci if (mslen != 48) 411cb0ef41Sopenharmony_ci return 0; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci /* At this point hash contains all handshake messages, update 441cb0ef41Sopenharmony_ci * with master secret and pad_1. 451cb0ef41Sopenharmony_ci */ 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci if (SHA1_Update(sha1, ms, mslen) <= 0) 481cb0ef41Sopenharmony_ci return 0; 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci /* Set padtmp to pad_1 value */ 511cb0ef41Sopenharmony_ci memset(padtmp, 0x36, sizeof(padtmp)); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci if (!SHA1_Update(sha1, padtmp, sizeof(padtmp))) 541cb0ef41Sopenharmony_ci return 0; 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci if (!SHA1_Final(sha1tmp, sha1)) 571cb0ef41Sopenharmony_ci return 0; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci /* Reinitialise context */ 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci if (!SHA1_Init(sha1)) 621cb0ef41Sopenharmony_ci return 0; 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci if (SHA1_Update(sha1, ms, mslen) <= 0) 651cb0ef41Sopenharmony_ci return 0; 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci /* Set padtmp to pad_2 value */ 681cb0ef41Sopenharmony_ci memset(padtmp, 0x5c, sizeof(padtmp)); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci if (!SHA1_Update(sha1, padtmp, sizeof(padtmp))) 711cb0ef41Sopenharmony_ci return 0; 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp))) 741cb0ef41Sopenharmony_ci return 0; 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci /* Now when ctx is finalised it will return the SSL v3 hash value */ 771cb0ef41Sopenharmony_ci OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp)); 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci return 1; 801cb0ef41Sopenharmony_ci} 81