@@ -104,30 +104,37 @@ static ngx_int_t
104
104
ngx_rtmp_make_digest (ngx_str_t * key , ngx_buf_t * src ,
105
105
u_char * skip , u_char * dst , ngx_log_t * log )
106
106
{
107
- static HMAC_CTX hmac ;
108
- static unsigned hmac_initialized ;
107
+ static HMAC_CTX * hmac ;
109
108
unsigned int len ;
110
109
111
- if (!hmac_initialized ) {
112
- HMAC_CTX_init (& hmac );
113
- hmac_initialized = 1 ;
110
+ if (hmac == NULL ) {
111
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
112
+ static HMAC_CTX shmac ;
113
+ hmac = & shmac ;
114
+ HMAC_CTX_init (hmac );
115
+ #else
116
+ hmac = HMAC_CTX_new ();
117
+ if (hmac == NULL ) {
118
+ return NGX_ERROR ;
119
+ }
120
+ #endif
114
121
}
115
122
116
- HMAC_Init_ex (& hmac , key -> data , key -> len , EVP_sha256 (), NULL );
123
+ HMAC_Init_ex (hmac , key -> data , key -> len , EVP_sha256 (), NULL );
117
124
118
125
if (skip && src -> pos <= skip && skip <= src -> last ) {
119
126
if (skip != src -> pos ) {
120
- HMAC_Update (& hmac , src -> pos , skip - src -> pos );
127
+ HMAC_Update (hmac , src -> pos , skip - src -> pos );
121
128
}
122
129
if (src -> last != skip + NGX_RTMP_HANDSHAKE_KEYLEN ) {
123
- HMAC_Update (& hmac , skip + NGX_RTMP_HANDSHAKE_KEYLEN ,
130
+ HMAC_Update (hmac , skip + NGX_RTMP_HANDSHAKE_KEYLEN ,
124
131
src -> last - skip - NGX_RTMP_HANDSHAKE_KEYLEN );
125
132
}
126
133
} else {
127
- HMAC_Update (& hmac , src -> pos , src -> last - src -> pos );
134
+ HMAC_Update (hmac , src -> pos , src -> last - src -> pos );
128
135
}
129
136
130
- HMAC_Final (& hmac , dst , & len );
137
+ HMAC_Final (hmac , dst , & len );
131
138
132
139
return NGX_OK ;
133
140
}
0 commit comments