Пример #1
0
void
main(void)
{

	blf_ctx c;
	char    key[] = "AAAAA";
	char    key2[] = "abcdefghijklmnopqrstuvwxyz";

	u_int32_t data[10];
	u_int32_t data2[] =
	{0x424c4f57l, 0x46495348l};

	u_int16_t i;

	/* First test */
	for (i = 0; i < 10; i++)
		data[i] = i;

	blf_key(&c, (u_int8_t *) key, 5);
	blf_enc(&c, data, 5);
	blf_dec(&c, data, 1);
	blf_dec(&c, data + 2, 4);
	printf("Should read as 0 - 9.\n");
	report(data, 10);

	/* Second test */
	blf_key(&c, (u_int8_t *) key2, strlen(key2));
	blf_enc(&c, data2, 1);
	printf("\nShould read as: 0x324ed0fe 0xf413a203.\n");
	report(data2, 2);
	blf_dec(&c, data2, 1);
	report(data2, 2);
}
Пример #2
0
void wtcc_blowfish(u8 *key, int keylen, int keytable, u8 *data, int datasz, int enc) {
    blf_ctx bfx;
    int     i;

    printf("- use keytable %u and key: ", keytable);
    for(i = 0; i < keylen; i++) {
        printf("%02x", key[i]);
    }
    printf("\n");

    wtcc_blowfish_key(&bfx, key, keylen, keytable);

    // NO padding!
    // datasz = (datasz + 7) & (~7);

    if(debug) {
        printf("- DEBUG wtcc_blowfish before (0x%x bytes):\n", datasz);
        show_dump(data, datasz, stdout);
    }

    if(enc == BF_ENCRYPT) {
        blf_enc(&bfx, (void *)data, datasz / 8);
    } else {
        blf_dec(&bfx, (void *)data, datasz / 8);
    }

    if(debug) {
        printf("- DEBUG wtcc_blowfish after:\n");
        show_dump(data, datasz, stdout);
    }
}
Пример #3
0
long CBlowfish_EnCode(const char* src,char* dest,unsigned long len)
{
	unsigned int i;
	for (i=0;i<len;i++)
		dest[i]=src[i];
	blf_enc(&c,(unsigned long*)dest,len/8);
	return CODE_SUCCESS;

}
Пример #4
0
static ERL_NIF_TERM bf_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
	ErlNifBinary state;
	uint32_t i, k, m;
	uint16_t j;
	uint8_t ciphertext[4 * BCRYPT_WORDS] = "OrpheanBeholderScryDoubt";
	uint32_t cdata[BCRYPT_WORDS];
	ERL_NIF_TERM encrypted[4 * BCRYPT_WORDS];

	/* Initialize our data from argv */
	if (argc != 1 || !enif_inspect_binary(env, argv[0], &state))
		return enif_make_badarg(env);

	/* This can be precomputed later */
	j = 0;
	for (i = 0; i < BCRYPT_WORDS; i++)
		cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_WORDS, &j);

	/* Now do the encryption */
	for (k = 0; k < 64; k++)
		blf_enc((blf_ctx *) state.data, cdata, BCRYPT_WORDS / 2);

	for (i = 0; i < BCRYPT_WORDS; i++) {
		ciphertext[4 * i + 3] = cdata[i] & 0xff;
		cdata[i] = cdata[i] >> 8;
		ciphertext[4 * i + 2] = cdata[i] & 0xff;
		cdata[i] = cdata[i] >> 8;
		ciphertext[4 * i + 1] = cdata[i] & 0xff;
		cdata[i] = cdata[i] >> 8;
		ciphertext[4 * i + 0] = cdata[i] & 0xff;
	}

	for (m = 0; m < BCRYPT_HASHLEN; m++) {
		encrypted[m] = enif_make_uint(env, ciphertext[m]);
	}
	secure_bzero(state.data, state.size);
	enif_release_binary(&state);
	secure_bzero(ciphertext, sizeof(ciphertext));
	secure_bzero(cdata, sizeof(cdata));
	return enif_make_list_from_array(env, encrypted, BCRYPT_HASHLEN);
}
Пример #5
0
		void createSharedPrinter(char *host, char *printer, int type)
		{
			blf_ctx ctx;
			hostent *ent;
			char msg[512], user[MAX_USERNAME_LENGTH + 1], password[BT_AUTH_TOKEN_LENGTH * 2 + 1];
			int length;

			// Abort if the printer type is not valid.
			if (type < 0 || type > 0)
				return;

			BRect frame = Frame();
			frame.top += 75;
			frame.left += 75;
			frame.bottom = frame.top + 135;
			frame.right = frame.left + 350;
			InstallPrinterPanel *prtPanel = new InstallPrinterPanel(frame, host, printer);
			status_t loginExit;
			wait_for_thread(prtPanel->Thread(), &loginExit);
			if (prtPanel->IsCancelled())
				return;

			// Get the IP address of the server.
			ent = gethostbyname(host);
			if (ent == NULL)
			{
				sprintf(msg, "The server %s, which hosts printer %s, cannot be found on the network.", host, printer);
				BAlert *alert = new BAlert("", msg, "OK");
				alert->Go();
				return;
			}

			unsigned int serverIP = ntohl(*((unsigned int *) ent->h_addr));

			if (getAuthentication(serverIP, printer))
			{
				BRect frame = Frame();
				frame.top += 75;
				frame.left += 75;
				frame.bottom = frame.top + 140;
				frame.right = frame.left + 250;
				LoginPanel *login = new LoginPanel(frame);
				status_t loginExit;
				wait_for_thread(login->Thread(), &loginExit);
				if (login->IsCancelled())
					return;

				// Copy the user name.
				strcpy(user, login->user);

				// Copy the user name and password supplied in the authentication dialog.
				sprintf(password, "%-*s%-*s", B_FILE_NAME_LENGTH, printer, MAX_USERNAME_LENGTH, login->user);
				length = strlen(password);
				assert(length == BT_AUTH_TOKEN_LENGTH);

				password[length] = 0;
				blf_key(&ctx, (unsigned char *) login->md5passwd, strlen(login->md5passwd));
				blf_enc(&ctx, (unsigned long *) password, length / 4);
			}
			else
				user[0] = password[0] = 0;

			prtPanel->CreatePrinter(printer, host, type, user, password);
			if (prtPanel->isDefault())
				prtPanel->SetDefaultPrinter(printer);
			if (prtPanel->printTestPage())
				prtPanel->TestPrinter(printer);
		}
Пример #6
0
		bool mountFileShare(uint32 address, char *share, const char *path)
		{
			blf_ctx ctx;
			mount_bt_params params;
			char hostname[256], msg[512], *folder;
			int length;
			port_id port;

			folder = strrchr(path, '/');
			if (folder)
				folder++;
			else
				folder = (char *) path;

			unsigned int serverIP = ntohl(address);

#ifndef BONE_VERSION
			if (!be_roster->IsRunning(KSOCKETD_SIGNATURE))
				if (be_roster->Launch(KSOCKETD_SIGNATURE) < B_NO_ERROR)
				{
					printf("Network communications could not be started.  The shared volume cannot be mounted.\n");
					BAlert *alert = new BAlert("", msg, "OK");
					alert->Go();
					return false;
				}

			for (int32 i = 0; i < 10; i++)
			{
				port = find_port(KSOCKET_DAEMON_NAME);
		
				if (port < B_NO_ERROR)
					snooze(1000000LL);
				else
					break;
			}

			if (port < B_NO_ERROR)
			{
				sprintf(msg, "Network communications are not responding.  The shared volume cannot be mounted.\n");
				BAlert *alert = new BAlert("", msg, "OK");
				alert->Go();
				return false;
			}
#endif

			// Handle user authentication
//			strcpy(user, crypt(user, "u0"));
//			strcpy(password, crypt(password, "p1"));
			if (getAuthentication(serverIP, share))
			{
				BRect frame = Frame();
				frame.top += 75;
				frame.left += 75;
				frame.bottom = frame.top + 140;
				frame.right = frame.left + 250;
				LoginPanel *login = new LoginPanel(frame);
				status_t loginExit;
				wait_for_thread(login->Thread(), &loginExit);
				if (login->IsCancelled())
					return false;

				// Copy the user name.
				strcpy(params.user, login->user);

				// Copy the user name and password supplied in the authentication dialog.
				sprintf(params.password, "%-*s%-*s", B_FILE_NAME_LENGTH, share, MAX_USERNAME_LENGTH, login->user);		//crypt(password, "p1"));
				length = strlen(params.password);
				assert(length == BT_AUTH_TOKEN_LENGTH);

				params.password[length] = 0;
				blf_key(&ctx, (unsigned char *) login->md5passwd, strlen(login->md5passwd));
				blf_enc(&ctx, (unsigned long *) params.password, length / 4);
			}
			else
				params.user[0] = params.password[0] = 0;

			params.serverIP = serverIP;
			params.server = host;
			params._export = share;
			params.folder = folder;
			params.uid = 0;
			params.gid = 0;

			gethostname(hostname, 256);
			params.hostname = hostname;

			int result = mount("beserved_client", path, NULL, 0, &params, sizeof(params));

			if (result < B_NO_ERROR)
			{
				sprintf(msg, "The shared volume could not be mounted (%s).\n", strerror(errno));
				BAlert *alert = new BAlert("", msg, "OK");
				alert->Go();
				return false;
			}

			return true;
		}