[Pkg-cryptsetup-devel] Bug#324353: howto improve usbcrypto.mkinitrd

Wesley W. Terpstra wesley at terpstra.ca
Mon Jan 23 12:19:19 UTC 2006


On Jan 22, 2006, at 6:40 PM, Jonas Meurer wrote:
> i've fixed the type in the shebang, and replaced /usr/local/bin/delay
> with /bin/sleep. but i'm not sure about how to replace xor. i even  
> don't
> know what it does in the mkinitrd script.

XOR takes two 32 byte (256 bit) files and bitwise XOR's them together.
XOR is perfectly secure for this use.

You can implement this in perl and/or C.
Maybe even shell...

Here's some perl that does it:
perl -e 'open(F2, at ARGV[0]) && open(F1, at ARGV[1]) or die "
Usage: $0 <file1> <file2>\n"; print $buf1 ^ $buf2 while (read (F1, 
$buf1,65536) &
& read (F2,$buf2,65536));' -- $STICKMNT/$STICKKEYDIR/$KEYNAME  
$HOSTKEYDIR/$HOSTK
EY | $CRYPTSETUP create $CRYPTVOLNAME $CRYPTRAWVOL

C:
/* Example without any error handling */
int main(int argc, char** argv) {
	FILE* f1 = fopen(argv[1], "r");
	FILE* f2 = fopen(argv[2], "r");
	unsigned char buf1[32], buf2[32];
	int i;

	fread(buf1, 32, 1, f1);
	fread(buf2, 32, 1, f2);
	
	for (i = 0; i < 32; ++i) buf1[i] ^= buf2[i];
	
	fwrite(buf1, 32, 1, stdout);
	return 0;
}	




More information about the Pkg-cryptsetup-devel mailing list