MCPcopy Create free account
hub / github.com/apache/brpc / openssl_HMACsha256

Function openssl_HMACsha256

src/brpc/policy/rtmp_protocol.cpp:148–178  ·  view source on GitHub ↗

Modified from code in SRS2 (src/protocol/srs_rtmp_handshake.cpp:94)

Source from the content-addressed store, hash-verified

146
147// Modified from code in SRS2 (src/protocol/srs_rtmp_handshake.cpp:94)
148int openssl_HMACsha256(const void* key, int key_size,
149 const void* data, int data_size, void* digest) {
150 if (NULL == EVP_sha256) {
151 LOG_ONCE(ERROR) << "Fail to find EVP_sha256, fall back to simple handshaking";
152 return -1;
153 }
154 unsigned int digest_size = 0;
155 unsigned char* temp_digest = (unsigned char*)digest;
156 if (key == NULL) {
157 // NOTE: first parameter of EVP_Digest in older openssl is void*.
158 if (EVP_Digest(const_cast<void*>(data), data_size, temp_digest,
159 &digest_size, EVP_sha256(), NULL) < 0) {
160 LOG(ERROR) << "Fail to EVP_Digest";
161 return -1;
162 }
163 } else {
164 // Note: following code uses HMAC_CTX previously which is ABI
165 // inconsistent in different version of openssl.
166 if (HMAC(EVP_sha256(), key, key_size,
167 (const unsigned char*) data, data_size,
168 temp_digest, &digest_size) == NULL) {
169 LOG(ERROR) << "Fail to HMAC";
170 return -1;
171 }
172 }
173 if (digest_size != 32) {
174 LOG(ERROR) << "digest_size=" << digest_size << " of sha256 is not 32";
175 return -1;
176 }
177 return 0;
178}
179
180// 68bytes FMS key for signing the sever packets.
181static const uint8_t GenuineFMSKey[] = {

Callers 2

ComputeDigestBaseMethod · 0.85
ComputeDigestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected