github.com/psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/upstreamproxy/go-ntlm/ntlm/crypto_test.go (about)

     1  //Copyright 2013 Thomson Reuters Global Resources. BSD License please see License file for more information
     2  
     3  package ntlm
     4  
     5  import (
     6  	"bytes"
     7  	"encoding/hex"
     8  	"testing"
     9  )
    10  
    11  func TestMd4(t *testing.T) {
    12  	data := []byte{1, 2, 3, 4, 5}
    13  	byteData, _ := hex.DecodeString("93ebafdfedd1994e8018cc295cc1a8ee")
    14  	if !bytes.Equal(md4(data), byteData) {
    15  		t.Error("MD4 result not correct")
    16  	}
    17  }
    18  
    19  func TestHmacMd5(t *testing.T) {
    20  	data := []byte{1, 2, 3, 4, 5}
    21  	byteData, _ := hex.DecodeString("9155578efbf3810a2adb4dee232a5fee")
    22  	if !bytes.Equal(hmacMd5(data, data), byteData) {
    23  		t.Error("HmacMd5 result not correct")
    24  	}
    25  }
    26  
    27  func TestNonce(t *testing.T) {
    28  	data := nonce(10)
    29  	if len(data) != 10 {
    30  		t.Error("Nonce is incorrect length")
    31  	}
    32  }
    33  
    34  func TestRc4K(t *testing.T) {
    35  	data := []byte{1, 2, 3, 4, 5}
    36  	key := []byte{1, 2, 3, 4, 5}
    37  	result, err := rc4K(key, data)
    38  	if err != nil {
    39  		// TODO: Need some sample data to test RC4K
    40  		//	t.Error("Error returned for RC4K")
    41  	}
    42  	if !bytes.Equal(result, data) {
    43  		//	t.Error("RC4K result not correct")
    44  	}
    45  }
    46  
    47  func TestDesL(t *testing.T) {
    48  	key, _ := hex.DecodeString("e52cac67419a9a224a3b108f3fa6cb6d")
    49  	message := []byte("12345678")
    50  	result, _ := desL(key, message)
    51  	expected, _ := hex.DecodeString("1192855D461A9754D189D8AE94D82488E3707C0662C0476A")
    52  	if !bytes.Equal(result, expected) {
    53  		t.Errorf("DesL did not produce correct result, got %s expected %s", hex.EncodeToString(result), hex.EncodeToString(expected))
    54  	}
    55  }
    56  
    57  func TestCRC32(t *testing.T) {
    58  	bytes := []byte("Discard medicine more than two years old.")
    59  	result := crc32(bytes)
    60  	expected := uint32(0x6b9cdfe7)
    61  	if expected != result {
    62  		t.Errorf("CRC 32 data is not correct got %d expected %d", result, expected)
    63  	}
    64  }