Beispiel #1
0
func (self *CipherCtx) DecryptInit(cipher *Cipher, key []byte, iv []byte) error {
	key_p := (*C.uchar)(unsafe.Pointer(C.CString(string(key))))
	defer C.free(unsafe.Pointer(key_p))
	iv_p := (*C.uchar)(unsafe.Pointer(C.CString(string(iv))))
	defer C.free(unsafe.Pointer(iv_p))

	ret := int(C.EVP_DecryptInit(
		self.evp_cipher_ctx, cipher.evp_cipher, key_p, iv_p))
	if ret == 1 {
		return nil
	}
	return errors.New("failure")
}
Beispiel #2
0
func (ctx *CipherCtx) DecryptInit(cipher *Cipher, key []byte, iv []byte) error {
	key_p := (*C.uchar)(unsafe.Pointer(C.CString(string(key))))
	defer C.free(unsafe.Pointer(key_p))
	iv_p := (*C.uchar)(unsafe.Pointer(C.CString(string(iv))))
	defer C.free(unsafe.Pointer(iv_p))

	ret := int(C.EVP_DecryptInit(
		ctx.evp_cipher_ctx, cipher.evp_cipher, key_p, iv_p))
	if ret != 1 {
		// try to return the openssl error first, if present
		if err := sslerr.Error(); err != nil {
			return err
		} else {
			return ErrFailure
		}
	}
	return nil
}