<commit_before>package hmaccrypt

import (
	"code.google.com/p/go.crypto/bcrypt"
	"crypto/rand"
	"crypto/sha512"
	"io"
	"testing"
)

func TestHmaccrypt(t *testing.T) {
	p := make([]byte, 64)
	if n, err := io.ReadFull(rand.Reader, p); err != nil {
		t.Fatalf("Error generating pepper: read %d of %d bytes, err %v", n, len(p), err)
	}
	op := make([]byte, 64)
	if n, err := io.ReadFull(rand.Reader, op); err != nil {
		t.Fatalf("Error generating pepper: read %d of %d bytes, err %v", n, len(op), err)
	}
	c := New(sha512.New, p)
	oc := New(sha512.New, op)
	pw := []byte("<PASSWORD>!")
	bd, err := c.Bcrypt(pw, bcrypt.MinCost)
	if err != nil {
		t.Fatalf("Error running c.bcrypt: %v", err)
	}
	obd, err := oc.Bcrypt(pw, bcrypt.MinCost)
	if err != nil {
		t.Fatalf("Error running oc.bcrypt: %v", err)
	}

	// Real digests should match
	if err := c.BcryptCompare(bd, pw); err != nil {
		t.Errorf("no c/bd/pw bcrypt match: %v", err)
	}
	if err := oc.BcryptCompare(obd, pw); err != nil {
		t.Errorf("no c/obd/pw bcrypt match: %v", err)
	}

	// Real digests with another password should not match
	if err := c.BcryptCompare(bd, []byte("f00b4r?")); err == nil {
		t.Errorf("bd/opw match")
	}

	// Digests from a HmacCrypt using another pepper should not match
	if err := c.BcryptCompare(obd, pw); err == nil {
		t.Errorf("c/obd/pw bcrypt match on hmac with another pepper")
	}
	if err := oc.BcryptCompare(bd, pw); err == nil {
		t.Errorf("oc/bd/pw bcrypt match on hmac with another pepper")
	}
}<commit_msg>Add test for HmacCrypt using the same hash/pepper, and HmacCrypt using the same hash, but another pepper<commit_after>package hmaccrypt

import (
	"code.google.com/p/go.crypto/bcrypt"
	"crypto/rand"
	"crypto/sha256"
	"crypto/sha512"
	"io"
	"testing"
)

func TestHmaccrypt(t *testing.T) {
	p := make([]byte, 64)
	if n, err := io.ReadFull(rand.Reader, p); err != nil {
		t.Fatalf("Error generating pepper: read %d of %d bytes, err %v", n, len(p), err)
	}
	op := make([]byte, 64)
	if n, err := io.ReadFull(rand.Reader, op); err != nil {
		t.Fatalf("Error generating pepper: read %d of %d bytes, err %v", n, len(op), err)
	}
	c := New(sha512.New, p)
	oc := New(sha512.New, op)
	pw := []byte("<PASSWORD>!")
	bd, err := c.Bcrypt(pw, bcrypt.MinCost)
	if err != nil {
		t.Fatalf("Error running c.bcrypt: %v", err)
	}
	obd, err := oc.Bcrypt(pw, bcrypt.MinCost)
	if err != nil {
		t.Fatalf("Error running oc.bcrypt: %v", err)
	}

	// Real digests should match
	if err := c.BcryptCompare(bd, pw); err != nil {
		t.Errorf("no c/bd/pw bcrypt match: %v", err)
	}
	if err := oc.BcryptCompare(obd, pw); err != nil {
		t.Errorf("no c/obd/pw bcrypt match: %v", err)
	}

	// Real digests with another password should not match
	if err := c.BcryptCompare(bd, []byte("f00b4r?")); err == nil {
		t.Error("bd/opw bcrypt match")
	}

	// Real digests from a HmacCrypt using the same hash function and pepper
	// should match
	nc := New(sha512.New, p)
	if err := nc.BcryptCompare(bd, pw); err != nil {
		t.Error("no nc/bd/pw bcrypt match")
	}

	// Real digests from a HmacCrypt using another hash function and the
	// same pepper should not match
	onc := New(sha256.New, p)
	if err := onc.BcryptCompare(bd, pw); err == nil {
		t.Error("onc/bd/pw bcrypt match")
	}

	// Real digests from a HmacCrypt using another pepper should not match
	if err := c.BcryptCompare(obd, pw); err == nil {
		t.Error("c/obd/pw bcrypt match (hmac with another pepper)")
	}
	if err := oc.BcryptCompare(bd, pw); err == nil {
		t.Error("oc/bd/pw bcrypt match (hmac with another pepper)")
	}
}
{'fraction_non_alphanumeric': 0.17236507487990957, 'fraction_numerical': 0.01158519355750212, 'mean_word_length': 3.5854922279792745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3694898', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1402, 'n_words': 414}