예제 #1
0
파일: sha512.go 프로젝트: runcom/gossl
func (d *digest) Sum(b []byte) []byte {
	buf := make([]C.uchar, d.Size())
	// make a copy of the pointer, so our context does not get freed.
	// this allows further writes.
	// TODO perhaps we should think about runtime.SetFinalizer to free the context?
	ctxTmp := C.SHA512_CTX(d.ctx)
	switch d.function {
	case crypto.SHA384:
		if C.SHA384_Final(&buf[0], &ctxTmp) != 1 {
			return make([]byte, 0)
		}
	default:
		if C.SHA512_Final(&buf[0], &ctxTmp) != 1 {
			return make([]byte, 0)
		}
	}
	var result []byte
	if b != nil {
		result = make([]byte, 0)
	} else {
		result = b
	}
	for _, value := range buf {
		result = append(result, byte(value))
	}
	return result
}
예제 #2
0
파일: sha.go 프로젝트: eftychis/crypto-1
func (h *sha512) Sum(b []byte) []byte {
	c := h.ctx
	d := make([]byte, C.SHA512_DIGEST_LENGTH)
	if C.SHA512_Final((*C.uchar)(unsafe.Pointer(&d[0])), &c) == 0 {
		panic("SHA512_Final failed")
	}
	return append(b, d...)
}
예제 #3
0
파일: sha512.go 프로젝트: postfix/go-ssl
func (self *SHA512Hash) Sum(b []byte) []byte {
	digest := make([]C.uchar, self.Size())
	if C.SHA512_Final(&digest[0], &self.sha) != 1 {
		panic("couldn't finalize digest")
	}
	var result []byte
	if b != nil {
		result = make([]byte, 0)
	} else {
		result = b
	}
	for _, value := range digest {
		result = append(result, byte(value))
	}
	return result
}
예제 #4
0
파일: sha512.go 프로젝트: partkyle/gossl
func (self *SHA512Hash) Sum(b []byte) []byte {
	digest := make([]C.uchar, self.Size())
	// make a copy of the pointer, so our context does not get freed.
	// this allows further writes.
	// TODO perhaps we should think about runtime.SetFinalizer to free the context?
	s_tmp := C.SHA512_CTX(self.sha)
	if C.SHA512_Final(&digest[0], &s_tmp) != 1 {
		panic("couldn't finalize digest")
	}
	var result []byte
	if b != nil {
		result = make([]byte, 0)
	} else {
		result = b
	}
	for _, value := range digest {
		result = append(result, byte(value))
	}
	return result
}