On 2015/6/2 21:45, Daniel P. Berrange wrote:
> +
> +static int qcrypto_cipher_encrypt_des_rfb(QCryptoCipher *cipher,
> + const void *in,
> + void *out,
> + size_t len,
> + Error **errp)
> +{
> + QCryptoCipherBuiltin *ctxt = cipher->opaque;
> + size_t i;
> +
> + deskey(ctxt->state.desrfb.key, EN0);
> +
Why not move the below check to top of deskey() ? and...
> + if (len % 8) {
> + error_setg(errp, _("Buffer size must be multiple of 8 not %zu"),
> + len);
> + return -1;
> + }
> +
> + for (i = 0; i < len; i += 8) {
> + des((void *)in + i, out + i);
> + }
> +
> + return 0;
> +}
> +
> +
> +static int qcrypto_cipher_decrypt_des_rfb(QCryptoCipher *cipher,
> + const void *in,
> + void *out,
> + size_t len,
> + Error **errp)
> +{
> + QCryptoCipherBuiltin *ctxt = cipher->opaque;
> + size_t i;
> +
> + deskey(ctxt->state.desrfb.key, DE1);
> +
...the same.
> + if (len % 8) {
> + error_setg(errp, _("Buffer size must be multiple of 8 not %zu"),
> + len);
> + return -1;
> + }
> +
> + for (i = 0; i < len; i += 8) {
> + des((void *)in + i, out + i);
> + }
> +
> + return 0;
> +}
Regards,
-Gonglei