lib/megar/crypto/aes_ctr.rb
def update(chunk)
    a32 = str_to_a32(chunk)
    last_i = 0

    (0..a32.size - 3).step(4) do |i|
      enc = Megar::Crypto::Aes.new(key: key).encrypt(iv)
      4.times do |m|
        a32[i+m] = (a32[i+m] || 0) ^ (enc[m] || 0)
      end
      iv[3] += 1
      iv[2] += 1 if iv[3] == 0
      last_i = i + 4
    end

    remainder = a32.size % 4

    if remainder > 0
      v = [0, 0, 0, 0]
      (last_i..a32.size - 1).step(1) { |m| v[m-last_i] = a32[m] || 0 }
      enc = Megar::Crypto::Aes.new(key: key).encrypt(iv)
      4.times { |m| v[m] = v[m] ^ enc[m] }

      (last_i..a32.size - 1).step(1) { |j| a32[j] = v[j - last_i] || 0 }
    end

    a32_to_str(a32)[0..chunk.size - 1]
  end
# Returns the encrypted binary string of +chunk+ (provided as binary string).
# Repeated calls will continue the counter sequence.
Returns the encrypted binary string of +chunk+ (provided as binary string).
Repeated calls will continue the counter sequence.
Returns the encrypted binary string of + chunk + ( provided as binary string ) . Repeated calls will continue the counter sequence .
def update(chunk)
    a32 = str_to_a32(chunk)
    last_i = 0
    (0..a32.size - 3).step(4) do |i|
      enc = Megar::Crypto::Aes.new(key: key).encrypt(iv)
      4.times do |m|
        a32[i+m] = (a32[i+m] || 0) ^ (enc[m] || 0)
      end
      iv[3] += 1
      iv[2] += 1 if iv[3] == 0
      last_i = i + 4
    end
    remainder = a32.size % 4
    if remainder > 0
      v = [0, 0, 0, 0]
      (last_i..a32.size - 1).step(1) { |m| v[m-last_i] = a32[m] || 0 }
      enc = Megar::Crypto::Aes.new(key: key).encrypt(iv)
      4.times { |m| v[m] = v[m] ^ enc[m] }
      (last_i..a32.size - 1).step(1) { |j| a32[j] = v[j - last_i] || 0 }
    end
    a32_to_str(a32)[0..chunk.size - 1]
  end
def update ( chunk ) a32 = str_to_a32 ( chunk ) last_i = 0 ( 0 .. a32 . size - 3 ) . step ( 4 ) do | i | enc = Megar :: Crypto :: Aes . new ( key : key ) . encrypt ( iv ) 4 . times do | m | a32 [ i + m ] = ( a32 [ i + m ] || 0 ) ^ ( enc [ m ] || 0 ) end iv [ 3 ] += 1 iv [ 2 ] += 1 if iv [ 3 ] == 0 last_i = i + 4 end remainder = a32 . size % 4 if remainder > 0 v = [ 0 , 0 , 0 , 0 ] ( last_i .. a32 . size - 1 ) . step ( 1 ) { | m | v [ m - last_i ] = a32 [ m ] || 0 } enc = Megar :: Crypto :: Aes . new ( key : key ) . encrypt ( iv ) 4 . times { | m | v [ m ] = v [ m ] ^ enc [ m ] } ( last_i .. a32 . size - 1 ) . step ( 1 ) { | j | a32 [ j ] = v [ j - last_i ] || 0 } end a32_to_str ( a32 ) [ 0 .. chunk . size - 1 ] end
Returns the encrypted binary string of +chunk+ (provided as binary string).
Returns the encrypted binary string of + chunk + ( provided as binary string ) .
chunk