Class: CyberplatPKI::IdeaCfb

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberplat_pki/idea_cfb.rb

Constant Summary collapse

BLOCK_SIZE =
8

Instance Method Summary collapse

Constructor Details

#initializeIdeaCfb

Returns a new instance of IdeaCfb.



7
8
9
10
11
12
13
# File 'lib/cyberplat_pki/idea_cfb.rb', line 7

def initialize
  @encbuf = "\0" * BLOCK_SIZE
  @fr     = "\0" * BLOCK_SIZE
  @fre    = "\0" * BLOCK_SIZE
  @pos    = 0
  @keys   = nil
end

Instance Method Details

#decrypt(data) ⇒ Object



28
29
30
# File 'lib/cyberplat_pki/idea_cfb.rb', line 28

def decrypt(data)
  cfb_engine data, method(:mix_dec), @idea.method(:decrypt_block)
end

#encrypt(data) ⇒ Object



23
24
25
# File 'lib/cyberplat_pki/idea_cfb.rb', line 23

def encrypt(data)
  cfb_engine data, method(:mix_enc), @idea.method(:encrypt_block)
end

#resyncObject



32
33
34
35
36
37
38
39
40
# File 'lib/cyberplat_pki/idea_cfb.rb', line 32

def resync
  if @pos != 0
    @fr[0...BLOCK_SIZE - @pos]          = @encbuf[@pos...BLOCK_SIZE]
    @fr[BLOCK_SIZE - @pos...BLOCK_SIZE] = @encbuf[0...@pos]

    @encbuf = "\0" * BLOCK_SIZE
    @pos = 0
  end
end

#start_decryption(key) ⇒ Object



19
20
21
# File 'lib/cyberplat_pki/idea_cfb.rb', line 19

def start_decryption(key)
  @idea = Crypt::IDEA.new key.unpack('n*'), Crypt::IDEA::DECRYPT
end

#start_encryption(key) ⇒ Object



15
16
17
# File 'lib/cyberplat_pki/idea_cfb.rb', line 15

def start_encryption(key)
  @idea = Crypt::IDEA.new key.unpack('n*'), Crypt::IDEA::ENCRYPT
end