func (h *sha256) Write(p []byte) (n int, err error) { l := len(p) if l > 0 && C.SHA256_Update(&h.ctx, unsafe.Pointer(&p[0]), C.size_t(l)) == 0 { panic("SHA256_Update failed") } return l, nil }
func (self *SHA256Hash) Write(msg []byte) (n int, err error) { size := C.size_t(len(msg)) if C.SHA256_Update(&self.sha, unsafe.Pointer(C.CString(string(msg))), size) != 1 { panic("problem updating hash") } return len(msg), nil }
func sum256(data []byte) []byte { var hash = make([]byte, 65) var sha256 C.SHA256_CTX C.SHA256_Init(&sha256) C.SHA256_Update(&sha256, unsafe.Pointer(&data[0]), C.size_t(len(data))) C.SHA256_Final((*C.uchar)(&hash[0]), &sha256) return hash[:64] }
func (d *digest) Write(msg []byte) (n int, err error) { mlen := len(msg) size := C.size_t(mlen) if d.is224 { if C.SHA224_Update(&d.ctx, unsafe.Pointer(C.CString(string(msg))), size) != 1 { return 0, sslerr.Error() } return mlen, nil } if C.SHA256_Update(&d.ctx, unsafe.Pointer(C.CString(string(msg))), size) != 1 { return 0, sslerr.Error() } return mlen, nil }