int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,

                          uint8_t *buf, int nb_sectors, bool enc,

                          Error **errp)

{

    union {

        uint64_t ll[2];

        uint8_t b[16];

    } ivec;

    int i;

    int ret;



    for(i = 0; i < nb_sectors; i++) {

        ivec.ll[0] = cpu_to_le64(sector_num);

        ivec.ll[1] = 0;

        if (qcrypto_cipher_setiv(s->cipher,

                                 ivec.b, G_N_ELEMENTS(ivec.b),

                                 errp) < 0) {

            return -1;

        }

        if (enc) {

            ret = qcrypto_cipher_encrypt(s->cipher,

                                         buf, buf,

                                         512,

                                         errp);

        } else {

            ret = qcrypto_cipher_decrypt(s->cipher,

                                         buf, buf,

                                         512,

                                         errp);

        }

        if (ret < 0) {

            return -1;

        }

        sector_num++;

        buf += 512;

    }

    return 0;

}

int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,

                          uint8_t *buf, int nb_sectors, bool enc,

                          Error **errp)

{

    union {

        uint64_t ll[2];

        uint8_t b[16];

    } ivec;

    int i;

    int ret;



    for(i = 0; i < nb_sectors; i++) {

        ivec.ll[0] = cpu_to_le64(sector_num);

        ivec.ll[1] = 0;

        if (qcrypto_cipher_setiv(s->cipher,

                                 ivec.b, G_N_ELEMENTS(ivec.b),

                                 errp) < 0) {

            return -1;

        }

        if (enc) {

            ret = qcrypto_cipher_encrypt(s->cipher,

                                         buf, buf,

                                         512,

                                         errp);

        } else {

            ret = qcrypto_cipher_decrypt(s->cipher,

                                         buf, buf,

                                         512,

                                         errp);

        }

        if (ret < 0) {

            return -1;

        }

        sector_num++;

        buf += 512;

    }

    return 0;

}

int FUNC_0(BDRVQcow2State *VAR_0, int64_t VAR_1,

                          uint8_t *VAR_2, int VAR_3, bool VAR_4,

                          Error **VAR_5)

{

    union {

        uint64_t ll[2];

        uint8_t b[16];

    } VAR_6;

    int VAR_7;

    int VAR_8;



    for(VAR_7 = 0; VAR_7 < VAR_3; VAR_7++) {

        VAR_6.ll[0] = cpu_to_le64(VAR_1);

        VAR_6.ll[1] = 0;

        if (qcrypto_cipher_setiv(VAR_0->cipher,

                                 VAR_6.b, G_N_ELEMENTS(VAR_6.b),

                                 VAR_5) < 0) {

            return -1;

        }

        if (VAR_4) {

            VAR_8 = qcrypto_cipher_encrypt(VAR_0->cipher,

                                         VAR_2, VAR_2,

                                         512,

                                         VAR_5);

        } else {

            VAR_8 = qcrypto_cipher_decrypt(VAR_0->cipher,

                                         VAR_2, VAR_2,

                                         512,

                                         VAR_5);

        }

        if (VAR_8 < 0) {

            return -1;

        }

        VAR_1++;

        VAR_2 += 512;

    }

    return 0;

}

int FUNC_0(BDRVQcow2State *VAR_0, int64_t VAR_1,
uint8_t *VAR_2, int VAR_3, bool VAR_4,
Error **VAR_5)
{ union { uint64_t ll[2]; uint8_t b[16]; } VAR_6; int VAR_7; int VAR_8; for(VAR_7 = 0; VAR_7 < VAR_3; VAR_7++) { VAR_6.ll[0] = cpu_to_le64(VAR_1); VAR_6.ll[1] = 0; if (qcrypto_cipher_setiv(VAR_0->cipher,
VAR_6.b, G_N_ELEMENTS(VAR_6.b),
VAR_5) < 0) { return -1; } if (VAR_4) { VAR_8 = qcrypto_cipher_encrypt(VAR_0->cipher,
VAR_2, VAR_2,
512,
VAR_5); } else { VAR_8 = qcrypto_cipher_decrypt(VAR_0->cipher,
VAR_2, VAR_2,
512,
VAR_5); } if (VAR_8 < 0) { return -1; } VAR_1++; VAR_2 += 512; } return 0; }