ige

package module
v0.0.0-...-493ac28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2018 License: MIT Imports: 4 Imported by: 1

README

ige

GoDoc Go Report Card Coverage

IGE block cipher mode for Go.

about

IGE is a block cipher mode usually used with AES. It's most notably used in Telegram's MTProto Protocol. It can be defined as the following function:

c_i = f_k(p_i ^ c_{i-1}) ^ p_{i-1}
  • c_i is ciphertext of the i block
  • p_i is plaintext of the i block
  • f_k is the block cipher function with k as the key

Here is a diagram of the above function:

Note that c_0 and m_0 in the diagram represent the initilization vectors. This implementation requires an initialization vector of two blocks. The first block is used as c_0. The second block is used as m_0.

testing

I'm using the test vectors described in the official OpenSSL IGE paper. You can execute the tests yourself by running:

$ go test
test vector 1
key
00010203 04050607 08090A0B 0C0D0E0F
initialization vector
00010203 04050607 08090A0B 0C0D0E0F
10111213 14151617 18191A1B 1C1D1E1F
plaintext
00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
ciphertext
1A8519A6 557BE652 E9DA8E43 DA4EF445
3CF456B4 CA488AA3 83C79C98 B34797CB
test vector 2
key
54686973 20697320 616E2069 6D706C65
initialization vector
6D656E74 6174696F 6E206F66 20494745
206D6F64 6520666F 72204F70 656E5353
plaintext
99706487 A1CDE613 BC6DE0B6 F24B1C7A
A448C8B9 C3403E34 67A8CAD8 9340F53B
ciphertext
4C2E204C 65742773 20686F70 65204265
6E20676F 74206974 20726967 6874210A

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidIV = errors.New("iv length must be: (block size * 2)")

ErrInvalidIV is displayed as the panic message if the initialization vector passed to NewIGEEncrypter or NewIGEDecrypter doesn't fulfill the length requirements for IGE.

IGE uses a two step xor process, so the first initialization vector is the first half, and the second initialization vector is the second half. This requires the initialization vector to be twice as long as the block size.

Functions

This section is empty.

Types

type IGE

type IGE interface {
	// BlockSize returns the mode's block size.
	BlockSize() int
	// CryptBlocks encrypts or decrypts a number of blocks based on the
	// underlying cipher.Block passed to NewIGEEncrypter or NewIGEDecrypter
	// (usually from crypto/aes).
	CryptBlocks(dst, src []byte)
}

IGE satisfies the cipher.BlockMode interface from the crypto/cipher package.

func NewIGEDecrypter

func NewIGEDecrypter(b cipher.Block, iv []byte) IGE

NewIGEDecrypter returns an IGE cipher.BlockMode which decrypts using IGE and the given cipher.Block.

Note: iv must contain two iv values for IGE (concatenated), otherwise this function will panic. See ErrInvalidIV for more information.

func NewIGEEncrypter

func NewIGEEncrypter(b cipher.Block, iv []byte) IGE

NewIGEEncrypter returns an IGE cipher.BlockMode which encrypts using IGE and the given cipher.Block.

Note: iv must contain two iv values for IGE (concatenated), otherwise this function will panic. See ErrInvalidIV for more information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL