<commit_before>/*
* Finished Message
* (C) 2004-2006,2012 <NAME>
*
* Released under the terms of the Botan license
*/

#include <botan/internal/tls_messages.h>
#include <botan/prf_tls.h>
#include <botan/hmac.h>
#include <botan/sha2_32.h>
#include <memory>

#include <stdio.h>

namespace Botan {

namespace {

KDF* choose_tls_prf(Version_Code version)
   {
   if(version == TLS_V10 || version == TLS_V11)
      return new TLS_PRF;
   else if(version == TLS_V12)
      return new TLS_12_PRF(new HMAC(new SHA_256)); // might depend on ciphersuite
   else
      throw TLS_Exception(PROTOCOL_VERSION,
                          "Unknown version for PRF");
   }

/*
* Compute the verify_data
*/
MemoryVector<byte> finished_compute_verify(TLS_Handshake_State* state,
                                           Connection_Side side)
   {
   if(state->version == SSL_V3)
      {
      const byte SSL_CLIENT_LABEL[] = { 0x43, 0x4C, 0x4E, 0x54 };
      const byte SSL_SERVER_LABEL[] = { 0x53, 0x52, 0x56, 0x52 };

      MemoryVector<byte> ssl3_finished;

      if(side == CLIENT)
         state->hash.update(SSL_CLIENT_LABEL, sizeof(SSL_CLIENT_LABEL));
      else
         state->hash.update(SSL_SERVER_LABEL, sizeof(SSL_SERVER_LABEL));

      return state->hash.final_ssl3(state->keys.master_secret());
      }
   else
      {
      const byte TLS_CLIENT_LABEL[] = {
         0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x66, 0x69, 0x6E, 0x69,<commit_msg>A change to Finished in 687c3c7dccdd2f5e4825bdb60155c7bfba22339f broke SSLv3 handshakes: we need to copy the handshake state when we computed the finished data in the SSLv3 case because we need to add a little bit of data onto the end, but we don't want to include that data with the next computation. This meant that the finished message a client sent us was fine, but the one we sent out had a bad finished value and was rejected.<commit_after>/*
* Finished Message
* (C) 2004-2006,2012 <NAME>
*
* Released under the terms of the Botan license
*/

#include <botan/internal/tls_messages.h>
#include <botan/prf_tls.h>
#include <botan/hmac.h>
#include <botan/sha2_32.h>
#include <memory>

#include <stdio.h>

namespace Botan {

namespace {

KDF* choose_tls_prf(Version_Code version)
   {
   if(version == TLS_V10 || version == TLS_V11)
      return new TLS_PRF;
   else if(version == TLS_V12)
      return new TLS_12_PRF(new HMAC(new SHA_256)); // might depend on ciphersuite
   else
      throw TLS_Exception(PROTOCOL_VERSION,
                          "Unknown version for PRF");
   }

/*
* Compute the verify_data
*/
MemoryVector<byte> finished_compute_verify(TLS_Handshake_State* state,
                                           Connection_Side side)
   {
   if(state->version == SSL_V3)
      {
      const byte SSL_CLIENT_LABEL[] = { 0x43, 0x4C, 0x4E, 0x54 };
      const byte SSL_SERVER_LABEL[] = { 0x53, 0x52, 0x56, 0x52 };

      TLS_Handshake_Hash hash = state->hash; // don't modify state

      MemoryVector<byte> ssl3_finished;

      if(side == CLIENT)
         hash.update(SSL_CLIENT_LABEL, sizeof(SSL_CLIENT_LABEL));
      else
         hash.update(SSL_SERVER_LABEL, sizeof(SSL_SERVER_LABEL));

      return hash.final_ssl3(state->keys.master_secret());
      }
   else
      {
      const byte TLS_CLIENT_LABEL[] = {
         0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x66, 0x69, 0x6E, 0x69,
{'fraction_non_alphanumeric': 0.10238805970149253, 'fraction_numerical': 0.05552238805970149, 'mean_word_length': 3.0083732057416266, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6919505', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1181, 'n_words': 297}