예제 #1
0
파일: ecc_driver.c 프로젝트: Abioy/orp
/** @brief call the ECC power ladder point-scalar multiply */
msel_status msel_ecc_mul(ecc_ctx_t* ctx)
{
#ifdef USE_SW_ECC

	// Get the scalar value
	make_mp(scalar, ctx->scalar, ECC_SCALAR_LEN);
	make_mp(compressed, ctx->point, ECC_POINT_LEN);

	// The sign of y is the 7th bit of the first byte
	int y_sign = ctx->point[0] & 0x01;
	point_uncompress(&in, compressed, y_sign);

	// Do the multiply
	point_scalar(&out, &in, scalar);

	// Compress the point -- this removes from mont. form
	point_compress(compressed, &y_sign, &out);
	ctx->point[0] &= 0xfe; ctx->point[0] |= y_sign;

	// Load the new point into the buffer
	from_mp(ctx->point, compressed, ECC_POINT_LEN);

    return MSEL_OK;
#else /* USE_SW_ECC */
    return arch_hw_ecc_mul(ctx);
#endif /* USE_SW_ECC */
}
예제 #2
0
rl_result_t
rl_roll_log(char *bdev)
{
    log_info_t		li;
    rl_result_t		rv = RL_SUCCESS;

    (void) memset((void *)&li, 0, (size_t)sizeof (li));
    if (is_mounted(&li, bdev) == RL_TRUE) {
        rv = rlflush(&li);
    } else {
        /*
         * Device appears not to be mounted.
         * We need to mount the device read only.
         * This automatically causes the log to be rolled, then we can
         * unmount the device again.  To do the mount, we need to
         * create a temporary directory, and then remove it when we
         * are done.
         */
        rv = make_mp(&li);
        switch (rv) {
        case RL_CORRUPT:
            /* corrupt mnttab - the file sys really was mounted */
            rv = rlflush(&li);
            break;
        case RL_SUCCESS:
            rv = rlmount(&li, RLM_RO);
            if (rv == RL_SUCCESS) {
                rv = rlflush(&li);
                if (umount(li.li_blkname) == SYSERR) {
                    (void) fprintf(stderr,
                                   "WARNING: rl_roll_log(): Can't unmount %s\n", li.li_blkname);
                }

            }
            break;
        }
    }
    cleanup(&li);
    return (rv);
}
예제 #3
0
rl_result_t
rl_log_control(char *bdev, int request)
{
    log_info_t	li;
    rl_result_t	rv = RL_SUCCESS;
    rl_result_t	alreadymounted;
    int		fd;
    fiolog_t	fl;
    int		logenabled = 0;

    if ((request != _FIOLOGENABLE) && (request != _FIOLOGDISABLE))
        return (RL_FAIL);

    (void) memset((void *)&li, '\0', (size_t)sizeof (li));
    if ((alreadymounted = is_mounted(&li, bdev)) != RL_TRUE) {
        /*
         * Device is not mounted. Need to mount it rw to allow
         * the log to be enabled/disabled. To do the mount, we need
         * to create a temporary directory, and then remove it when
         * we are done.
         */
        if (make_mp(&li) != RL_SUCCESS) {
            cleanup(&li);
            return (RL_FAIL);
        }
        if (rlmount(&li, RLM_RW) != RL_SUCCESS) {
            cleanup(&li);
            return (RL_FAIL);
        }
    }

    if (alreadymounted == RL_TRUE)
        fd = open(li.li_mntpoint, O_RDONLY);
    else
        fd = open(li.li_tmpmp, O_RDONLY);
    if (fd == SYSERR) {
        perror("open");
        rv = RL_SYSERR;
        goto out;
    }

    fl.nbytes_requested = 0;
    fl.nbytes_actual = 0;
    fl.error = FIOLOG_ENONE;

    if (ioctl(fd, request, &fl) == SYSERR) {
        perror("ioctl");
        (void) close(fd);
        rv = RL_SYSERR;
        goto out;
    }
    if (ioctl(fd, _FIOISLOG, &logenabled) == SYSERR) {
        perror("ioctl");
        (void) close(fd);
        rv = RL_SYSERR;
        goto out;
    }
    if (((request == _FIOLOGENABLE) && (!logenabled)) ||
            ((request == _FIOLOGDISABLE) && logenabled))
        rv = RL_FAIL;

    (void) close(fd);
out:
    if (alreadymounted != RL_TRUE)
        (void) rlumount(&li);
    cleanup(&li);
    return (rv);
}