Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC Tests failing #1

Open
aarondl opened this issue Oct 15, 2019 · 0 comments
Open

RFC Tests failing #1

aarondl opened this issue Oct 15, 2019 · 0 comments

Comments

@aarondl
Copy link

aarondl commented Oct 15, 2019

Hello there.

I added the RFC tests cited here: https://tools.ietf.org/html/rfc4269.html

It appears that this library fails all of them. I didn't want to fork & PR so here's the tests I wrote:

func TestRFCVectors(t *testing.T) {
	t.Parallel()

	tests := []struct {
		Key []byte
		PT  []byte
		CT  []byte
	}{
		{
			Key: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
			PT:  []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
			CT:  []byte{0x5E, 0xBA, 0xC6, 0xE0, 0x05, 0x4E, 0x16, 0x68, 0x19, 0xAF, 0xF1, 0xCC, 0x6D, 0x34, 0x6C, 0xDB},
		},
		{
			Key: []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
			PT:  []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
			CT:  []byte{0xC1, 0x1F, 0x22, 0xF2, 0x01, 0x40, 0x50, 0x50, 0x84, 0x48, 0x35, 0x97, 0xE4, 0x37, 0x0F, 0x43},
		},
		{
			Key: []byte{0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8, 0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85},
			PT:  []byte{0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D},
			CT:  []byte{0xEE, 0x54, 0xD1, 0x3E, 0xBC, 0xAE, 0x70, 0x6D, 0x22, 0x6B, 0xC3, 0x14, 0x2C, 0xD4, 0x0D, 0x4A},
		},
		{
			Key: []byte{0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D, 0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7},
			PT:  []byte{0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7},
			CT:  []byte{0x9B, 0x9B, 0x7B, 0xFC, 0xD1, 0x81, 0x3C, 0xB9, 0x5D, 0x0B, 0x36, 0x18, 0xF4, 0x0F, 0x51, 0x22},
		},
	}

	for i, test := range tests {
		c, err := NewCipher(test.Key)
		if err != nil {
			panic(err)
		}

		gotEncrypt := make([]byte, c.BlockSize())
		c.Encrypt(gotEncrypt, test.PT)

		if !bytes.Equal(gotEncrypt, test.CT) {
			t.Errorf("%d) failed encryption\nwant: %X\n got: %X\n", i, test.CT, gotEncrypt)
		}

		gotDecrypt := make([]byte, c.BlockSize())
		c.Decrypt(gotDecrypt, test.CT)

		if !bytes.Equal(gotDecrypt, test.PT) {
			t.Errorf("%d) failed decryption\nwant: %X\n got: %X\n", i, test.PT, gotDecrypt)
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant