//Construct a new instance. see crypto/aes // returning a block cipher that satisfies the crypto/cipher.Block interface func NewCipher(key []byte) (cipher.Block, error) { aes := new(aesKey) key_p := pointerFromBytes(key) key_bits := C.int(len(key) * 8) if ret := C.AES_set_encrypt_key(key_p, key_bits, &aes._aes_encrypt_key); ret != 0 { // in case the error is something deep in OpenSSL land if err := sslerr.Error(); err != nil { return aes, err } if ret == -1 { return aes, errorInvalidKey } if ret == -2 { return aes, errorWrongSizeKey } // standard fallback error return aes, errorSettingKey } if ret := C.AES_set_decrypt_key(key_p, key_bits, &aes._aes_decrypt_key); ret != 0 { // in case the error is something deep in OpenSSL land if err := sslerr.Error(); err != nil { return aes, err } if ret == -1 { return aes, errorInvalidKey } if ret == -2 { return aes, errorWrongSizeKey } // standard fallback error return aes, errorSettingKey } return aes, nil }
//Construct a new instance. see crypto/aes func NewCipher(key []byte) (cipher.Block, error) { aes := new(AESKey) key_p := pointerFromBytes(key) key_bits := C.int(len(key) * 8) if C.AES_set_encrypt_key(key_p, key_bits, &aes._aes_encrypt_key) != 0 { return aes, errors.New("problem setting key") } if C.AES_set_decrypt_key(key_p, key_bits, &aes._aes_decrypt_key) != 0 { return aes, errors.New("problem setting key") } return aes, nil }