Skip to content

Commit 653f911

Browse files
committed
An IV should be generated for each encryption
We now have the ability to decide if the IV is communicated to the client in a non forgeable manner or we only keep it on the server side. Closes #2
1 parent 99662f8 commit 653f911

3 files changed

+270
-20
lines changed

src/ngx_http_encrypted_session_cipher.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "ngx_http_encrypted_session_cipher.h"
1414
#include <openssl/evp.h>
15+
#include <openssl/hmac.h>
1516
#include <openssl/md5.h>
1617
#include <stdint.h>
1718

@@ -291,3 +292,21 @@ ngx_http_encrypted_session_htonll(uint64_t n)
291292
+ htonl((unsigned long) (n >> 32));
292293
#endif
293294
}
295+
296+
unsigned char*
297+
ngx_http_encrypted_session_hmac(ngx_pool_t *pool,
298+
const u_char *key, size_t key_len,
299+
const u_char *data, size_t data_len, u_char **dst, size_t *dst_len)
300+
{
301+
u_char *result = NULL;
302+
u_char *input = ngx_pcalloc(pool, data_len + 1);
303+
ngx_memcpy(input, data, data_len);
304+
305+
unsigned int len;
306+
result = HMAC(EVP_sha256(), key, key_len, input, data_len, result, &len);
307+
*dst_len = len;
308+
*dst = (u_char*)ngx_pcalloc(pool, len + 1);
309+
ngx_memcpy(*dst, result, len);
310+
311+
return *dst;
312+
}

src/ngx_http_encrypted_session_cipher.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ngx_core.h>
66
#include <ngx_http.h>
77
#include <openssl/evp.h>
8+
#include <openssl/hmac.h>
89

910

1011
typedef int (*cipher_ctx_reset_handle) (EVP_CIPHER_CTX *ctx);
@@ -34,6 +35,10 @@ ngx_int_t ngx_http_encrypted_session_aes_mac_decrypt(
3435
size_t key_len, const u_char *in, size_t in_len, u_char **dst,
3536
size_t *dst_len);
3637

38+
unsigned char* ngx_http_encrypted_session_hmac(
39+
ngx_pool_t *pool,
40+
const u_char *key, size_t key_len,
41+
const u_char *data, size_t data_len, u_char **dst, size_t *dst_len);
3742

3843
#endif /* NGX_HTTP_ENCRYPTED_SESSION_CIPHER_H */
3944

0 commit comments

Comments
 (0)