Beispiel #1
0
	EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) override
	{
		if (!md5)
			return EVENT_CONTINUE;

		Encryption::Context *context = md5->CreateContext();
		context->Update(reinterpret_cast<const unsigned char *>(src.c_str()), src.length());
		context->Finalize();

		Encryption::Hash hash = context->GetFinalizedHash();

		char digest[32], digest2[16];
		memset(digest, 0, sizeof(digest));
		if (hash.second > sizeof(digest))
			throw CoreException("Hash too large");
		memcpy(digest, hash.first, hash.second);

		for (int i = 0; i < 32; i += 2)
			digest2[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]);

		Anope::string buf = "oldmd5:" + Anope::Hex(digest2, sizeof(digest2));

		Log(LOG_DEBUG_2) << "(enc_old) hashed password from [" << src << "] to [" << buf << "]";
		dest = buf;
		delete context;
		return EVENT_ALLOW;
	}
Beispiel #2
0
/* Encrypt `src' of length `len' and store the result in `dest'.  If the
 * resulting string would be longer than `size', return -1 and leave `dest'
 * unchanged; else return 0.
 */
static int myencrypt(const char *src, int len, char *dest, int size)
{

#ifdef ENCRYPT_MD5

    md5_state_t context;
    char digest[33];
    char dest2[16];
    int i;

    if (size < 32)
        return -1;

    memset(&context, 0, sizeof(context));
    memset(&digest, 0, sizeof(digest));

    md5_init(&context);
    md5_append(&context, (unsigned const char *) src, (size_t) len);
    md5_finish(&context, (unsigned char *) digest);

    for (i = 0; i < 32; i += 2)
        dest2[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]);

    /* convert to hex, skipping last 8 bytes (constant) -- jilles */
    strcpy(dest, "$ircservices$");
    for (i = 0; i <= 7; i++)
	sprintf(dest + 13 + 2 * i, "%02x", 255 & dest2[i]);
    return 0;

#else

    return -1;                  /* unknown encryption algorithm */

#endif

}
Beispiel #3
0
void
sincosl(long double x, long double *s, long double *c) {
	long double y[2], z = 0.0L;
	int n, ix;
#if defined(__i386) || defined(__amd64)
	int *px = (int *) &x;
#endif

	/* trig(Inf or NaN) is NaN */
	if (!finitel(x)) {
		*s = *c = x - x;
		return;
	}

	/* High word of x. */
#if defined(__i386) || defined(__amd64)
	XTOI(px, ix);
#else
	ix = *(int *) &x;
#endif

	/* |x| ~< pi/4 */
	ix &= 0x7fffffff;
	if (ix <= 0x3ffe9220)
		*s = __k_sincosl(x, z, c);

	/* argument reduction needed */
	else {
		n = __rem_pio2l(x, y);
		switch (n & 3) {
		case 0:
			*s = __k_sincosl(y[0], y[1], c);
			break;
		case 1:
			*c = -__k_sincosl(y[0], y[1], s);
			break;
		case 2:
			*s = -__k_sincosl(y[0], y[1], c);
			*c = -*c;
			break;
		case 3:
			*c = __k_sincosl(y[0], y[1], s);
			*s = -*s;
		}
	}
}
Beispiel #4
0
/* INDENT ON */
long double
__k_sinl(long double x, long double y) {
	long double a, t, z, w;
	int *pt = (int *) &t, *px = (int *) &x;
	int i, j, hx, ix;

	t = 1.0L;
#if !defined(__i386) && !defined(__amd64)
	hx = px[0];
#else
	XTOI(px, hx);
#endif
	ix = hx & 0x7fffffff;
	if (ix < 0x3ffc9000) {
		if (ix < 0x3fc60000)
			if (((int) x) == 0)
				return (x);	/* generate inexact */
		z = x * x;
		t = z * (p1 + z * (p2 + z * (p3 + z * (p4 + z * (p5 + z *
			(p6 + z * (p7 + z * p8)))))));
		t = y + x * t;
		return (x + t);
	}
	j = (ix + 0x400) & 0x7ffff800;
	i = (j - 0x3ffc4000) >> 11;
#if !defined(__i386) && !defined(__amd64)
	pt[0] = j;
#else
	ITOX(j, pt);
#endif
	if (hx > 0)
		x = y - (t - x);
	else
		x = (-y) - (t + x);
	a = _TBL_sinl_hi[i];
	z = x * x;
	t = z * (qq1 + z * (qq2 + z * (qq3 + z * (qq4 + z * qq5))));
	w = x * (one + z * (pp1 + z * (pp2 + z * (pp3 + z * (pp4 + z *
		pp5)))));
	t = _TBL_cosl_hi[i] * w + a * t;
	t += _TBL_sinl_lo[i];
	if (hx < 0)
		return (-a - t);
	else
		return (a + t);
}
Beispiel #5
0
/*  *********************************************************************
    *  ui_cmd_flashop(cmd,argc,argv)
    *  
    *  The 'flashop' command lives here.  This command does a variety
    *  of flash operations over a range of bytes:
    *
    *  erase, protect, unprotect
    *  
    *  Input parameters: 
    *  	   cmd - command table entry
    *  	   argc,argv - parameters
    *  	   
    *  Return value:
    *  	   0 if ok
    *  	   else error
    ********************************************************************* */
static int ui_cmd_flashop(ui_cmdline_t *cmd,int argc,char *argv[])
{
    int fd;
    int res;
    char *flashdev;
    int devtype;
    flash_info_t flashinfo;
    int erase;
    int protect;
    int unprotect;
    int retlen;
    unsigned int startaddr = 0;
    unsigned int endaddr = 0;
    char *x;
    int all;
    flash_range_t range;

    flashdev = cmd_getarg(cmd,0);

    if (!flashdev) flashdev = "flash0";

    /*
     * Make sure it's a flash device.
     */

    res = cfe_getdevinfo(flashdev);
    if (res < 0) {
        return ui_showerror(CFE_ERR_DEVNOTFOUND,flashdev);
        }

    devtype = res & CFE_DEV_MASK;

    if (res != CFE_DEV_FLASH) {
        xprintf("Device '%s' is not a flash device.\n",flashdev);
        return CFE_ERR_INV_PARAM;
    }

    protect = cmd_sw_isset(cmd,"-protect");
    unprotect = cmd_sw_isset(cmd,"-unprotect");
    erase = cmd_sw_isset(cmd,"-erase");

    if (protect == 1) {
        if (erase || unprotect)
            {
            xprintf("Conflicting options\n");
            return CFE_ERR_INV_PARAM;
            }
    }

    if (unprotect == 1) {
        if (erase || protect)
            {
            xprintf("Conflicting options\n");
            return CFE_ERR_INV_PARAM;
            }
    }

    if (erase == 1) {
        if (unprotect || protect)
            {
            xprintf("Conflicting options\n");
            return CFE_ERR_INV_PARAM;
            }
    }

    if (erase == 0 && protect == 0 && unprotect == 0) {
        xprintf("Need one of following options: -erase -protect -unprotect\n");
        return CFE_ERR_INV_PARAM;
    }


    fd = cfe_open(flashdev);
    if (fd < 0) {
	xprintf("Could not open device '%s'\n",flashdev);
	return CFE_ERR_DEVNOTFOUND;
	}

    res = cfe_ioctl(fd,IOCTL_FLASH_GETINFO,(uint8_t *) &flashinfo,sizeof(flash_info_t),&retlen,0);
    if (res != 0) {
        cfe_close (fd);
        return CFE_ERR_IOERR;
    }

    all = cmd_sw_isset(cmd,"-all");
    if (all == 0) {
        if (cmd_sw_value(cmd,"-startaddr",&x)) {
            startaddr = XTOI(x);
            }
        else {
            xprintf("Need option: -startaddr\n");
            cfe_close (fd);
            return CFE_ERR_INV_PARAM;
            }

        if (cmd_sw_value(cmd,"-endaddr",&x)) {
            endaddr = XTOI(x);
            }
        else {
            xprintf("Need option: -endaddr\n");
            cfe_close (fd);
            return CFE_ERR_INV_PARAM;
            }

        if (startaddr > endaddr) {
            xprintf("Final offset (endaddr) must not be less than startaddr \n");
            cfe_close (fd);
            return CFE_ERR_INV_PARAM;
            }
       
        /* Make sure endaddr is within flash */

        if (endaddr >= flashinfo.flash_size) {
            xprintf("Final offset (endaddr) must less than 0x%x\n", flashinfo.flash_size);
            cfe_close (fd);
            return CFE_ERR_INV_PARAM;
        }

        /* We got here, so params are OK  */
        range.range_base = startaddr;
        range.range_length = endaddr-startaddr;
    }
    else {
        range.range_base = 0;
        range.range_length = flashinfo.flash_size;
    }

    if (erase)
        {
        res = cfe_ioctl(fd, IOCTL_FLASH_ERASE_RANGE,
            (void *) &range, NULL, NULL, NULL);
        }

    else if (protect)
        {
        res = cfe_ioctl(fd, IOCTL_FLASH_PROTECT_RANGE,
            (void *) &range, NULL, NULL, NULL);
        }

    else if (unprotect)
        {
        res = cfe_ioctl(fd, IOCTL_FLASH_UNPROTECT_RANGE,
            (void *) &range, NULL, NULL, NULL);
        }

    if (res != 0) {
        printf("ioctl error\n");
        }

    cfe_close (fd);
    return 0;
}