コード例 #1
0
int
UB_mod_exp(BIGNUM *res, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx)
{
    struct crypt_kop kop;
    u_int8_t *ale, *ble, *cle;
    static int crypto_fd = -1;

    if (crypto_fd == -1 && ioctl(devcrypto(), CRIOGET, &crypto_fd) == -1)
        err(1, "CRIOGET");

    if ((ale = bignum_to_le(a, NULL)) == NULL)
        err(1, "bignum_to_le, a");
    if ((ble = bignum_to_le(b, NULL)) == NULL)
        err(1, "bignum_to_le, b");
    if ((cle = bignum_to_le(c, NULL)) == NULL)
        err(1, "bignum_to_le, c");

    bzero(&kop, sizeof(kop));
    kop.crk_op = CRK_MOD_EXP;
    kop.crk_iparams = 3;
    kop.crk_oparams = 1;
    kop.crk_crid = crid;
    kop.crk_param[0].crp_p = ale;
    kop.crk_param[0].crp_nbits = BN_num_bytes(a) * 8;
    kop.crk_param[1].crp_p = ble;
    kop.crk_param[1].crp_nbits = BN_num_bytes(b) * 8;
    kop.crk_param[2].crp_p = cle;
    kop.crk_param[2].crp_nbits = BN_num_bytes(c) * 8;
    kop.crk_param[3].crp_p = cle;
    kop.crk_param[3].crp_nbits = BN_num_bytes(c) * 8;

    if (ioctl(crypto_fd, CIOCKEY2, &kop) == -1)
        err(1, "CIOCKEY2");
    if (verbose)
        printf("device = %s\n", crfind(kop.crk_crid));

    bzero(ale, BN_num_bytes(a));
    free(ale);
    bzero(ble, BN_num_bytes(b));
    free(ble);

    if (kop.crk_status != 0) {
        printf("error %d\n", kop.crk_status);
        bzero(cle, BN_num_bytes(c));
        free(cle);
        return (-1);
    } else {
        res = le_to_bignum(res, cle, BN_num_bytes(c));
        bzero(cle, BN_num_bytes(c));
        free(cle);
        if (res == NULL)
            err(1, "le_to_bignum");
        return (0);
    }
    return (0);
}
コード例 #2
0
int CMAC::crget()
{
    int fd;

    if (ioctl(devcrypto(), CRIOGET, &fd) == -1)
        err(1, "line %d:ioctl(CRIOGET)", __LINE__);
    if (fcntl(fd, F_SETFD, 1) == -1)
        err(1, "fcntl(F_SETFD) (crget)");
    return fd;
}
コード例 #3
0
ファイル: cryptotest.c プロジェクト: JabirTech/Source
static int
crget(void)
{
    int fd;

    if (ioctl(devcrypto(), CRIOGET, &fd) == -1)
        err(1, "ioctl(CRIOGET)");
    if (fcntl(fd, F_SETFD, 1) == -1)
        err(1, "fcntl(F_SETFD) (crget)");
    return fd;
}
コード例 #4
0
ファイル: cryptotest.c プロジェクト: JabirTech/Source
static const char *
crfind(int crid)
{
    static struct crypt_find_op find;

    bzero(&find, sizeof(find));
    find.crid = crid;
    if (ioctl(devcrypto(), CRIOFINDDEV, &find) == -1)
        err(1, "ioctl(CIOCFINDDEV): crid %d", crid);
    return find.name;
}
コード例 #5
0
ファイル: cryptotest.c プロジェクト: JabirTech/Source
static int
crlookup(const char *devname)
{
    struct crypt_find_op find;

    find.crid = -1;
    strlcpy(find.name, devname, sizeof(find.name));
    if (ioctl(devcrypto(), CIOCFINDDEV, &find) == -1)
        err(1, "ioctl(CIOCFINDDEV)");
    return find.crid;
}