Module: Yubikey::AES

Defined in:
ext/yubikey_ext/yubikey_ext.c

Class Method Summary collapse

Class Method Details

.decrypt(state, key) ⇒ Object

Decrypt 16 bytes of binary AES ciphertext to binary plaintext with the Yubico implementation of AES-128 ECB

state

16 bytes of binary ciphertext

key

16-byte binary key



14
15
16
17
18
19
20
21
22
23
24
25
# File 'ext/yubikey_ext/yubikey_ext.c', line 14

static VALUE
aes_decrypt(VALUE self, VALUE state, VALUE key) {
  char* state_ptr = StringValuePtr(state);
  char* key_ptr = StringValuePtr(key);
  
  if (RSTRING(state)->len != YUBIKEY_BLOCK_SIZE || RSTRING(key)->len != YUBIKEY_KEY_SIZE)
    rb_raise(rb_eArgError, "key and state must be 16 bytes");
  
  yubikey_aes_decrypt((uint8_t*)state_ptr, (uint8_t*)key_ptr);
  
  return rb_str_new(state_ptr, YUBIKEY_BLOCK_SIZE);
}