One obvious problem is that
output is a local variable that goes out of scope when the function exits. You need to dynamically allocate
output. You may have been planing to do that, but did not show it. The problem with doing that is that it places the burden of releasing the buffer upon the caller. It would be better to have the caller provide the output buffer and pass it as an argument.
I suspect you're running into argument differences between your wrapper and the encryption routines. I'm not familiar with the specific routines you're using. I use the SHA512 routines.
The calling sequences are:
1 2 3 4 5 6 7
|
extern int SHA256Reset(SHA256Context *);
extern int SHA256Input(SHA256Context *, const uint8_t *bytes,
unsigned int bytecount);
extern int SHA256FinalBits(SHA256Context *, const uint8_t bits,
unsigned int bitcount);
extern int SHA256Result(SHA256Context *,
uint8_t Message_Digest[SHA256HashSize]);
|
There are also SHA384 and SHA512 routines. The calling sequences are the same.
The SHAxxx routines are a one-way hash. There is no decrypting the result.
I would expect that your AES-256-CBC routines would have similar calling sequences.
Note that Context is passed to each call. You call SHAxxxReset to clear the context before you start. Note that these routines need to know how long the input message is. You don't provide that.
edit:
A quick google came up with the following calling sequence, pretty much identical to the above:
|
void AES_CBC_encrypt_buffer(struct AES_ctx *ctx,uint8_t* buf, uint32_t length)
|