Class: RubyClangFpe::Fpe31Key

Inherits:
FpeKey
  • Object
show all
Defined in:
ext/ruby_clang_fpe/ruby_clang_fpe.c

Instance Method Summary collapse

Methods inherited from FpeKey

generate_ff1_key, generate_ff3_1_key, generate_ff3_key, generate_key, #radix, #tweak

Instance Method Details

#decrypt(ciphertext) ⇒ Object



67
68
69
70
71
72
73
74
# File 'ext/ruby_clang_fpe/ruby_clang_fpe.c', line 67

static VALUE t_ff3_decrypt(VALUE self, VALUE ciphertext)
{
  FPE_KEY *fpe_key_ptr;
  TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
  char plaintext[strlen(StringValueCStr(ciphertext))];
  FPE_ff3_decrypt(StringValuePtr(ciphertext), plaintext, fpe_key_ptr);
  return rb_str_new_cstr(plaintext);
};

#encrypt(plaintext) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'ext/ruby_clang_fpe/ruby_clang_fpe.c', line 57

static VALUE t_ff3_encrypt(VALUE self, VALUE plaintext)
{
  FPE_KEY *fpe_key_ptr;
  TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
  char *plaintext_str = StringValueCStr(plaintext);
  char ciphertext[strlen(plaintext_str)];
  FPE_ff3_encrypt(plaintext_str, ciphertext, fpe_key_ptr);
  return rb_str_new_cstr(ciphertext);
};