Ejemplo n.º 1
0
func doWork(proc chanproc, id int) {
	start := time.Now()
	for {
		select {
		case pass := <-proc.mdp:
			{
				tmp := md4.New()
				tmp.Write(pass)
				tmp.Sum(nil)
			}
		case <-proc.nomorejob:
			{
				if len(proc.mdp) != 0 {
					for i := 0; i < len(proc.mdp); i++ {
						tmp := md4.New()
						tmp.Write(<-proc.mdp)
						tmp.Sum(nil)
					}
				}
				proc.temps <- time.Since(start)
				return
			}
		}
	}
}
Ejemplo n.º 2
0
func (otp *OTP) hashCalc(algorithm string) ([8]byte, error) {
	var hash_algorithm hash.Hash

	tmpseq := STAITC_OTP_OTP_REP_COUNT - (otp.seq % STAITC_OTP_OTP_REP_COUNT)
	_string_ := strconv.Itoa(otp.seed) + otp.passphrase

	switch otp.mAlgorithm {
	case "MD4":
		hash_algorithm = md4.New()
	case "MD5":
		hash_algorithm = md5.New()
	case "RIPEMD128":
		hash_algorithm = ripemd128.New()
	case "RIPEMD160":
		hash_algorithm = ripemd160.New()
	case "SHA1":
		hash_algorithm = sha1.New()
	default:
		return [8]byte{0, 0, 0, 0, 0, 0, 0, 0}, fmt.Errorf("NoSuchAlgorithmException: %s", otp.mAlgorithm)
	}

	hash_algorithm.Reset()
	hash_algorithm.Write(UCS2_to_UTF8([]byte(_string_)))
	otp.hash = hashValueTo8(hash_algorithm.Sum(nil))

	for tmpseq > 0 {
		hash_algorithm.Reset()
		hash_algorithm.Write(otp.hash[:])
		otp.hash = hashValueTo8(hash_algorithm.Sum(nil))
		tmpseq--
	}

	return otp.hash, nil
}
Ejemplo n.º 3
0
func (s *descbc) Decrypt(salt []byte, algo, usage int, data []byte) ([]byte, error) {
	var h hash.Hash

	switch algo {
	case cryptDesCbcMd5:
		h = md5.New()
	case cryptDesCbcMd4:
		h = md4.New()
	default:
		return nil, ErrProtocol
	}

	if (len(data) & 7) != 0 {
		return nil, ErrProtocol
	}

	iv := [8]byte{}
	b, _ := des.NewCipher(s.key)
	c := cipher.NewCBCDecrypter(b, iv[:])
	c.CryptBlocks(data, data)

	chk := make([]byte, h.Size())
	h.Write(data[:8])
	h.Write(chk) // Just need h.Size() zero bytes instead of the checksum
	h.Write(data[8+len(chk):])
	h.Sum(chk[:0])

	if subtle.ConstantTimeCompare(chk, data[8:8+len(chk)]) != 1 {
		return nil, ErrProtocol
	}

	return data[8+len(chk):], nil
}
Ejemplo n.º 4
0
func doWork(proc chanproc) {
	//i := NBHASH / NBPROC
	for {
		pass := <-proc.pass
		tmp := md4.New()
		tmp.Write(pass)
		//fmt.Println(proc.id, " pass : "******" len pass ", len(proc.pass))
		tmp.Sum(nil)
		/*
				f, err := os.OpenFile("testlogfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
				if err != nil {
				    t.Fatalf("error opening file: %v", err)
				}
				defer f.Close()

				log.SetOutput(f)
				log.Println("This is a test log entry")


			i--
			if i == 0 {
				proc.temps <- time.Since(start)
				return
			}*/
	}
}
Ejemplo n.º 5
0
func doWork(mdp chan []byte, done chan bool) {
	for {
		tmp := md4.New()
		tmp.Write(<-mdp)
		tmp.Sum(nil)
		done <- true
	}
}
Ejemplo n.º 6
0
Archivo: md4.go Proyecto: cch123/test
func test() {

	s1 := "Hello, MD4 test text"
	ctx := md4.New()
	ctx.Write([]byte(s1))
	hash = ctx.Sum(nil)

}
Ejemplo n.º 7
0
func (s *descbc) Sign(algo, usage int, data ...[]byte) ([]byte, error) {
	var h hash.Hash

	switch algo {
	case signGssDes:
		sz := 0
		for _, d := range data {
			sz += len(d)
		}
		sz = (sz + 7) &^ 7
		u := make([]byte, sz)
		v := u[:0]
		for _, d := range data {
			v = append(v, d...)
		}

		iv := [8]byte{}
		b, _ := des.NewCipher(s.key)
		c := cipher.NewCBCEncrypter(b, iv[:])
		c.CryptBlocks(u, u)
		return u[len(u)-8:], nil

	case signGssMd5Des:
		h = md5.New()
		for _, d := range data {
			h.Write(d)
		}
		return s.Sign(signGssDes, usage, h.Sum(nil))

	case signMd5Des:
		h = md5.New()
	case signMd4Des:
		h = md4.New()
	default:
		return unkeyedSign(algo, usage, data...)
	}

	var key [8]byte
	for i := 0; i < 8; i++ {
		key[i] = s.key[i] ^ 0xF0
	}

	chk := make([]byte, 24)
	io.ReadFull(rand.Reader, chk[:8])

	h.Write(chk[:8])
	for _, d := range data {
		h.Write(d)
	}
	h.Sum(chk[8:])

	iv := [8]byte{}
	b, _ := des.NewCipher(s.key)
	c := cipher.NewCBCEncrypter(b, iv[:])
	c.CryptBlocks(chk, chk)
	return chk, nil
}
Ejemplo n.º 8
0
func createWork(work chan hash.Hash, scanner *bufio.Scanner, done chan bool) {
	for scanner.Scan() {

		tmp2 := []byte(scanner.Text())
		//fmt.Println(tmp2, "plop")

		tmp := md4.New()
		tmp.Write(tmp2)
		work <- tmp
	}
	fmt.Println("CREATION FINI ! ")
	done <- true
} /*
Ejemplo n.º 9
0
func makeHash(name string) hash.Hash {
	switch strings.ToLower(name) {
	case "ripemd160":
		return ripemd160.New()
	case "md4":
		return md4.New()
	case "md5":
		return md5.New()
	case "sha1":
		return sha1.New()
	case "sha256":
		return sha256.New()
	case "sha384":
		return sha512.New384()
	case "sha3-224":
		return sha3.New224()
	case "sha3-256":
		return sha3.New256()
	case "sha3-384":
		return sha3.New384()
	case "sha3-512":
		return sha3.New512()
	case "sha512":
		return sha512.New()
	case "sha512-224":
		return sha512.New512_224()
	case "sha512-256":
		return sha512.New512_256()
	case "crc32-ieee":
		return crc32.NewIEEE()
	case "crc64-iso":
		return crc64.New(crc64.MakeTable(crc64.ISO))
	case "crc64-ecma":
		return crc64.New(crc64.MakeTable(crc64.ECMA))
	case "adler32":
		return adler32.New()
	case "fnv32":
		return fnv.New32()
	case "fnv32a":
		return fnv.New32a()
	case "fnv64":
		return fnv.New64()
	case "fnv64a":
		return fnv.New64a()
	case "xor8":
		return new(xor8)
	case "fletch16":
		return &fletch16{}
	}
	return nil
}
Ejemplo n.º 10
0
func hashChunks(input <-chan Chunk, output chan<- Chunk, wg *sync.WaitGroup) {
	defer wg.Done()
	hasher := md4.New()
	for {
		chunk, ok := <-input
		if !ok {
			return
		}

		hasher.Reset()
		hasher.Write(chunk.bytes)
		chunk.hash = hasher.Sum(nil)
		output <- chunk
	}
}
Ejemplo n.º 11
0
func doWork(proc chanproc) {
	i := NBHASH / NBPROC
	start := time.Now()
	for {
		tmp := md4.New()
		tmp.Write(proc.currentPass)
		tmp.Sum(nil)

		i--
		if i == 0 {
			proc.temps <- time.Since(start)
			return
		}
		proc.NextPass()
	}
}
Ejemplo n.º 12
0
// rc4HmacKey converts a UTF8 password into a key suitable for use with the
// rc4hmac.
func rc4HmacKey(password string) []byte {
	// Convert password from UTF8 to UTF16-LE
	s := make([]byte, 0)
	for _, r := range password {
		if r > 0x10000 {
			a, b := utf16.EncodeRune(r)
			s = append(s, byte(a), byte(a>>8), byte(b), byte(b>>8))
		} else {
			s = append(s, byte(r), byte(r>>8))
		}
	}

	h := md4.New()
	h.Write(s)
	return h.Sum(nil)
}
Ejemplo n.º 13
0
func unkeyedSign(algo, usage int, data ...[]byte) ([]byte, error) {
	var h hash.Hash

	switch algo {
	case signMd5:
		h = md5.New()
	case signMd4:
		h = md4.New()
	default:
		return nil, ErrProtocol
	}

	for _, d := range data {
		h.Write(d)
	}
	return h.Sum(nil), nil

}
Ejemplo n.º 14
0
func Hash(reader io.Reader, oldMethod bool) (string, error) {
	chunks := make(chan Chunk, 50)
	hashes := make(chan Chunk, 50)

	go readChunksToChannel(reader, chunks)

	var wg sync.WaitGroup
	for i := 0; i < runtime.NumCPU(); i++ {
		wg.Add(1)
		go hashChunks(chunks, hashes, &wg)
	}

	processedChan := make(chan CorrelatedChunks)
	go correlateChunksToMap(hashes, processedChan)
	wg.Wait()
	close(hashes)

	correlatedChunks := <-processedChan
	hashList := make([]byte, 16*len(correlatedChunks.chunkMap))

	for position, hash := range correlatedChunks.chunkMap {
		copy(hashList[position*16:(position+1)*16], hash)
	}

	hasher := md4.New()
	if correlatedChunks.totalBytes%BLOCK_SIZE == 0 && oldMethod == true {
		hasher.Reset()
		hasher.Write([]byte{})
		hashList = hasher.Sum(hashList)
	}

	var finalSum []byte
	if len(hashList) > 16 {
		hasher.Reset()
		hasher.Write(hashList)
		finalSum = hasher.Sum(nil)
	} else {
		finalSum = hashList
	}

	return hex.EncodeToString(finalSum), nil

}
Ejemplo n.º 15
0
func (s *descbc) Encrypt(salt []byte, usage int, data ...[]byte) []byte {
	var h hash.Hash

	switch s.etype {
	case cryptDesCbcMd5:
		h = md5.New()
	case cryptDesCbcMd4:
		h = md4.New()
	default:
		panic("")
	}

	outsz := 8 + h.Size()
	for _, d := range data {
		outsz += len(d)
	}
	outsz = (outsz + 7) &^ 7
	out := make([]byte, outsz)

	io.ReadFull(rand.Reader, out[:8])

	v := out[8+h.Size():]
	for _, d := range data {
		n := copy(v, d)
		v = v[n:]
	}

	h.Write(out)
	h.Sum(out[:8])

	iv := [8]byte{}
	b, _ := des.NewCipher(s.key)
	c := cipher.NewCBCEncrypter(b, iv[:])
	c.CryptBlocks(out, out)

	return out
}
Ejemplo n.º 16
0
func getNtlm(password string) []byte {
	cipher := md4.New()
	cipher.Write(utf16FromString(password))
	return cipher.Sum(nil)
}
Ejemplo n.º 17
0
// MD4 hash the UCS-2 value
func ntPasswordHash(r []byte) []byte {
	d := md4.New()
	d.Write(r)
	return d.Sum(nil)
}
Ejemplo n.º 18
0
// HashNtPasswordHash
// Hash the MD4 to a hashhash MD4
func hashNtPasswordHash(hash []byte) []byte {
	d := md4.New()
	d.Write(hash)
	return d.Sum(nil)
}
Ejemplo n.º 19
0
func getNtlmHash(password string) []byte {
	hash := md4.New()
	hash.Write(toUnicode(password))
	return hash.Sum(nil)
}
Ejemplo n.º 20
0
Archivo: ed2k.go Proyecto: sunclx/ed2k
func New() hash.Hash {
	d := new(digest)
	d.inner = md4.New()
	d.total = md4.New()
	return d
}
Ejemplo n.º 21
0
func ntlmHash(password string) (hash [21]byte) {
	h := md4.New()
	h.Write(utf16le(password))
	h.Sum(hash[:0])
	return
}