derive mac, write, and iv keys for server and client, see page 34, 6.2.2
| 1037 | |
| 1038 | // derive mac, write, and iv keys for server and client, see page 34, 6.2.2 |
| 1039 | void SSL::deriveKeys() |
| 1040 | { |
| 1041 | int length = 2 * secure_.get_parms().hash_size_ + |
| 1042 | 2 * secure_.get_parms().key_size_ + |
| 1043 | 2 * secure_.get_parms().iv_size_; |
| 1044 | int rounds = (length + MD5_LEN - 1 ) / MD5_LEN; |
| 1045 | input_buffer key_data(rounds * MD5_LEN); |
| 1046 | |
| 1047 | opaque sha_output[SHA_LEN]; |
| 1048 | opaque md5_input[SECRET_LEN + SHA_LEN]; |
| 1049 | opaque sha_input[KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN]; |
| 1050 | |
| 1051 | MD5 md5; |
| 1052 | SHA sha; |
| 1053 | |
| 1054 | memcpy(md5_input, secure_.get_connection().master_secret_, SECRET_LEN); |
| 1055 | |
| 1056 | for (int i = 0; i < rounds; ++i) { |
| 1057 | int j = i + 1; |
| 1058 | if (!setPrefix(sha_input, i)) { |
| 1059 | SetError(prefix_error); |
| 1060 | return; |
| 1061 | } |
| 1062 | |
| 1063 | memcpy(&sha_input[j], secure_.get_connection().master_secret_, |
| 1064 | SECRET_LEN); |
| 1065 | memcpy(&sha_input[j+SECRET_LEN], |
| 1066 | secure_.get_connection().server_random_, RAN_LEN); |
| 1067 | memcpy(&sha_input[j + SECRET_LEN + RAN_LEN], |
| 1068 | secure_.get_connection().client_random_, RAN_LEN); |
| 1069 | sha.get_digest(sha_output, sha_input, |
| 1070 | sizeof(sha_input) - KEY_PREFIX + j); |
| 1071 | |
| 1072 | memcpy(&md5_input[SECRET_LEN], sha_output, SHA_LEN); |
| 1073 | md5.get_digest(key_data.get_buffer() + i * MD5_LEN, |
| 1074 | md5_input, sizeof(md5_input)); |
| 1075 | } |
| 1076 | storeKeys(key_data.get_buffer()); |
| 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | // derive mac, write, and iv keys for server and client |
no test coverage detected