Class: OpenSSL::Cipher

Inherits:
Object
  • Object
show all
Defined in:
ext/openssl/cipher/aead/aead.c

Defined Under Namespace

Classes: CipherError

Instance Method Summary collapse

Instance Method Details

#aad=(data) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/openssl/cipher/aead/aead.c', line 64

static VALUE
ossl_cipher_set_aad(VALUE self, VALUE data)
{
    EVP_CIPHER_CTX *ctx;
    char           *in      = NULL;
    int             in_len  = 0;
    int             out_len = 0;

    StringValue(data);

    in     = (unsigned char *) RSTRING_PTR(data);
    in_len = RSTRING_LEN(data);

    GetCipher(self, ctx);

    if (!EVP_CipherUpdate(ctx, NULL, &out_len, in, in_len))
        ossl_raise(eCipherError, NULL);

    return self;
}

#gcm_iv_len=(iv_length) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'ext/openssl/cipher/aead/aead.c', line 129

static VALUE
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
    ossl_raise(eCipherError, "your version of OpenSSL doesn't support GCM");
#else
    if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, ivlen, NULL))
        ossl_raise(eCipherError, NULL);
#endif

    return iv_length;
}

#gcm_tagObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/openssl/cipher/aead/aead.c', line 85

static VALUE
ossl_cipher_get_tag(VALUE self)
{
    EVP_CIPHER_CTX *ctx;
    VALUE           tag;

    tag = rb_str_new(NULL, 16);

    GetCipher(self, ctx);

#ifndef EVP_CTRL_GCM_GET_TAG
    ossl_raise(eCipherError, "your version of OpenSSL doesn't support GCM");
#else
    if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, (unsigned char *)RSTRING_PTR(tag)))
        ossl_raise(eCipherError, NULL);
#endif

    return tag;
}

#gcm_tag=(data) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'ext/openssl/cipher/aead/aead.c', line 105

static VALUE
ossl_cipher_set_tag(VALUE self, VALUE data)
{
    EVP_CIPHER_CTX *ctx;
    char           *in     = NULL;
    int             in_len = 0;

    StringValue(data);

    in     = (unsigned char *) RSTRING_PTR(data);
    in_len = RSTRING_LEN(data);

    GetCipher(self, ctx);

#ifndef EVP_CTRL_GCM_SET_TAG
    ossl_raise(eCipherError, "your version of OpenSSL doesn't support GCM");
#else
    if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, in_len, in))
        ossl_raise(eCipherError, NULL);
#endif

    return data;
}

#verifyObject



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'ext/openssl/cipher/aead/aead.c', line 147

static VALUE
ossl_cipher_verify(VALUE self)
{
    EVP_CIPHER_CTX *ctx;
    int             out_len = 0;

    GetCipher(self, ctx);

    if (!EVP_CipherUpdate(ctx, NULL, &out_len, NULL, 0))
        ossl_raise(eCipherError, "ciphertext failed authentication step");

    return rb_str_new(0, 0);
}