File: Blowfish.xs

package info (click to toggle)
libcrypt-blowfish-perl 2.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 168 kB
  • ctags: 48
  • sloc: ansic: 790; perl: 237; makefile: 2
file content (78 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 *	Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/)
 *
 *      Code Modfifications Copyright (C) 2000 W3Works, LLC (http://www.w3works.co/)
 *	All rights reserved.
 */

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "blowfish.h"

/*  thanks to LDS */
#ifndef sv_undef
#define sv_undef PL_sv_undef
#endif

MODULE = Crypt::Blowfish		PACKAGE = Crypt::Blowfish		PREFIX = blowfish_

PROTOTYPES: DISABLE

 
char *
blowfish_init(key)
	unsigned char *	key = NO_INIT
	STRLEN	key_len = NO_INIT
    CODE:
	{
		/*
		* What should this length be???
		*/
		char ks[8192];

		key = (unsigned char *) SvPV(ST(0), key_len);
		if (key_len < 8 || key_len > 56)
			croak("Invalid length key");

		if (blowfish_make_bfkey(key, key_len, ks))
			croak("Error creating key schedule");

		ST(0) = sv_2mortal(newSVpv(ks, sizeof(ks)));
	}

void
blowfish_crypt(input, output, ks, dir)
	char *	input = NO_INIT
	SV *	output
	char *	ks = NO_INIT
	STRLEN	input_len = NO_INIT
	STRLEN	output_len = NO_INIT
	STRLEN	ks_len = NO_INIT
	int		dir
	CODE:
	{
		input = (char *) SvPV(ST(0), input_len);
		if (input_len != 8)
			croak("input must be 8 bytes long");

		ks = (char *) SvPV(ST(2), ks_len);

		if (output == &sv_undef)
			output = sv_newmortal();
		output_len = 8;

		(SvUPGRADE(output, SVt_PV));

		/* blowfish_crypt_8bytes(input, SvGROW(output, 8), ks, dir); */
		/* HP-UX (HP cc) fix below, thanks Addi! */
		blowfish_crypt_8bytes( (unsigned char*)input, (unsigned char*)SvGROW(output, 8), ks, (short)dir);

		SvCUR_set(output, output_len);
		*SvEND(output) = '\0';
		(void) SvPOK_only(output);
		SvTAINT(output);

		ST(0) = output;
	}