Beispiel #1
0
func (h *sha1) Sum(b []byte) []byte {
	c := h.ctx
	d := make([]byte, C.SHA_DIGEST_LENGTH)
	if C.SHA1_Final((*C.uchar)(&d[0]), &c) == 0 {
		panic("SHA1_Final failed")
	}
	return append(b, d...)
}
Beispiel #2
0
func (d *digest) Sum(in []byte) []byte {
	context := *d.context
	defer func() { *d.context = context }()

	md := make([]byte, Size)
	if C.SHA1_Final((*_Ctype_unsignedchar)(&md[0]), d.context) == 1 {
		return append(in, md...)
	}

	return nil
}
Beispiel #3
0
func (self *SHA1Hash) Sum(b []byte) []byte {
	digest := make([]C.uchar, self.Size())
	if C.SHA1_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
}
Beispiel #4
0
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.SHA_CTX(d.ctx)
	if C.SHA1_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
}
Beispiel #5
0
func (self *SHA1Hash) 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.SHA_CTX(self.sha)
	if C.SHA1_Final(&digest[0], &s_tmp) != 1 {
		// TODO maybe not panic here?
		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
}
Beispiel #6
0
func (ctx *ShaContext) Final() []byte {
	result := make([]byte, C.SHA_DIGEST_LENGTH)
	C.SHA1_Final((*C.uchar)(&result[0]), (*C.SHA_CTX)(ctx))
	return result
}