Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.1
1.8.2
50 changes: 27 additions & 23 deletions ext/openssl/cipher/aead/aead.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#include <ruby.h>
#include <ruby/version.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

VALUE dOSSL;
VALUE eCipherError;

#define GetCipherInit(obj, ctx) do { \
Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \
} while (0)
#if RUBY_API_VERSION_CODE >= 20200
#define GetCipherInit(obj, ctx) do { \
TypedData_Get_Struct((obj), EVP_CIPHER_CTX, RTYPEDDATA_TYPE(obj), (ctx)); \
} while (0)
#else
#define GetCipherInit(obj, ctx) do { \
Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \
} while (0)
#endif

#define GetCipher(obj, ctx) do { \
GetCipherInit((obj), (ctx)); \
if (!(ctx)) { \
ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \
} \
} while (0)
#define GetCipher(obj, ctx) do { \
GetCipherInit((obj), (ctx)); \
if (!(ctx)) { \
ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \
} \
} while (0)

static VALUE
ossl_make_error(VALUE exc, const char *fmt, va_list args)
Expand Down Expand Up @@ -65,7 +72,7 @@ static VALUE
ossl_cipher_set_aad(VALUE self, VALUE data)
{
EVP_CIPHER_CTX *ctx;
char *in = NULL;
unsigned char *in = NULL;
int in_len = 0;
int out_len = 0;

Expand Down Expand Up @@ -106,7 +113,7 @@ static VALUE
ossl_cipher_set_tag(VALUE self, VALUE data)
{
EVP_CIPHER_CTX *ctx;
char *in = NULL;
unsigned char *in = NULL;
int in_len = 0;

StringValue(data);
Expand All @@ -131,7 +138,6 @@ ossl_cipher_set_iv_length(VALUE self, VALUE iv_length)
{
EVP_CIPHER_CTX *ctx;
int ivlen = NUM2INT(iv_length);

GetCipher(self, ctx);

#ifndef EVP_CTRL_GCM_SET_IVLEN
Expand Down Expand Up @@ -161,15 +167,13 @@ ossl_cipher_verify(VALUE self)
void
Init_aead(void)
{
VALUE mOSSL = rb_define_module("OpenSSL");
VALUE mOSSLCipher = rb_define_class_under(mOSSL, "Cipher", rb_cObject);
VALUE eOSSLError = rb_define_class_under(mOSSL,"OpenSSLError",rb_eStandardError);

eCipherError = rb_define_class_under(mOSSLCipher, "CipherError", eOSSLError);

rb_define_method(mOSSLCipher, "aad=", ossl_cipher_set_aad, 1);
rb_define_method(mOSSLCipher, "gcm_tag", ossl_cipher_get_tag, 0);
rb_define_method(mOSSLCipher, "gcm_tag=", ossl_cipher_set_tag, 1);
rb_define_method(mOSSLCipher, "gcm_iv_len=", ossl_cipher_set_iv_length, 1);
rb_define_method(mOSSLCipher, "verify", ossl_cipher_verify, 0);
rb_require("openssl");
VALUE cOSSLCipher = rb_path2class("OpenSSL::Cipher");
eCipherError = rb_path2class("OpenSSL::Cipher::CipherError");

rb_define_method(cOSSLCipher, "aad=", ossl_cipher_set_aad, 1);
rb_define_method(cOSSLCipher, "gcm_tag", ossl_cipher_get_tag, 0);
rb_define_method(cOSSLCipher, "gcm_tag=", ossl_cipher_set_tag, 1);
rb_define_method(cOSSLCipher, "gcm_iv_len=", ossl_cipher_set_iv_length, 1);
rb_define_method(cOSSLCipher, "verify", ossl_cipher_verify, 0);
}
1 change: 0 additions & 1 deletion lib/aead/cipher.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'aead'

require 'openssl'
require 'openssl/cipher/aead'
require 'securerandom'

Expand Down