Package: hashalot / 0.3-8

10_avoid_direct_changes.patch Patch series | 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Description: avoid direct changes in upstream source code.
Author: Joao Eriberto Mota Filho <eriberto@debian.org>
Last-Update: 2016-01-18
--- hashalot-0.3.orig/hashalot.1
+++ hashalot-0.3/hashalot.1
@@ -2,15 +2,24 @@
 .SH NAME
 hashalot \- read a passphrase and print a hash
 .SH SYNOPSIS
-.B  hashalot [ \-s SALT ] [ \-x ] [ \-n #BYTES ] HASHTYPE
+.B  hashalot [ \-s SALT ] [ \-x ] [ \-n #BYTES ] [ -q ] [ HASHTYPE ]
 .br
-.B  HASHTYPE [ \-s SALT ] [ \-x ] [ \-n #BYTES ]
+.B  HASHTYPE [ \-s SALT ] [ \-x ] [ \-n #BYTES ] [ -q ]
 .SH DESCRIPTION
 .PP
 \fIhashalot\fP is a small tool that reads a passphrase from standard
 input, hashes it using the given hash type, and prints the result to
 standard output.
 .PP
+\fBWarning\fP: If you do not use the \fB\-x\fP option, the hash is
+printed in binary. This may wedge your terminal settings, or even force
+you to log out.
+.PP
+This is not a general purpose hasher, only the first line is used, not even
+including the final newline.  Thus, don't be surprised if the output seems
+to be different from other tools -- you'd have to hash exactly the same
+string.
+.PP
 Supported values for \fIHASHTYPE\fP:
 .br
 .RS 8
@@ -18,7 +27,6 @@ ripemd160 rmd160 rmd160compat sha256 sha
 .RE
 .PP
 .SH OPTIONS
-.l
 The option
 .B \-s \fISALT\fP
 specifies an initialization vector to the hashing algorithm. You need
@@ -36,6 +44,12 @@ option can be used to limit (or increase
 default is as appropriate for the specified hash algorithm: 20 bytes for
 RIPEMD160, 32 bytes for SHA256, etc. The default for the "rmd160compat"
 hash is 16 bytes, for compatibility with the old kerneli.org utilities.
+.PP
+The
+.B \-q
+option causes
+.B hashalot
+to be more quiet and not print some warnings which may be superfluous.
 .SH AUTHOR
 Ben Slusky <sluskyb@paranoiacs.org>
 .PP
--- hashalot-0.3.orig/hashalot.c
+++ hashalot-0.3/hashalot.c
@@ -28,25 +28,28 @@
 #include "rmd160.h"
 #include "sha512.h"
 
-#define PASSWDBUFFLEN 130
-
 typedef int (*phash_func_t)(char dest[], size_t dest_len, const char src[], size_t src_len);
 
+static void *
+xmalloc (size_t size);
+
 static int
 phash_rmd160(char dest[], size_t dest_len, const char src[], size_t src_len)
 {
-	char tmp[PASSWDBUFFLEN] = { 'A', 0, };
 	char key[RMD160_HASH_SIZE * 2] = { 0, };
+	char *tmp = xmalloc(src_len + 2);
+	tmp[0] = 'A';
+	tmp[1] = '\0';
 
-	strncpy(tmp + 1, src, PASSWDBUFFLEN - 1);
-	tmp[PASSWDBUFFLEN - 1] = '\0';
+	strncpy(tmp + 1, src, src_len);
+	tmp[src_len + 1] = '\0';
   
 	rmd160_hash_buffer(key, src, src_len);
-	rmd160_hash_buffer(key + RMD160_HASH_SIZE, tmp, src_len + 1 /* dangerous! */);
+	rmd160_hash_buffer(key + RMD160_HASH_SIZE, tmp, src_len + 1);
 
 	memcpy(dest, key, dest_len);
 
-	memset (tmp, 0, PASSWDBUFFLEN);        /* paranoia */
+	memset (tmp, 0, src_len + 2);        /* paranoia */
 	memset (key, 0, RMD160_HASH_SIZE * 2); /* paranoia */
 
 	return dest_len;
@@ -182,7 +185,7 @@ xmalloc (size_t size) {
 /* function to append a "salt" to the passphrase, to better resist
  * dictionary attacks */
 static char *
-salt_passphrase(char *pass, char *salt) {
+salt_passphrase(char *pass, const char *salt) {
 	char *buf = xmalloc(strlen(pass) + strlen(salt) + 1);
 	sprintf(buf, "%s%s", pass, salt);
 
@@ -213,8 +216,9 @@ main(int argc, char *argv[])
 	size_t hashlen = 0;
 	phash_func_t func;
 	int hex_output = 0, c;
+	int quiet = 0;
 
-	while ((c = getopt(argc, argv, "n:s:x")) != -1) {
+	while ((c = getopt(argc, argv, "n:s:qx")) != -1) {
 		switch (c) {
 		case 'n':
 			hashlen = strtoul(optarg, &p, 0);
@@ -229,6 +233,9 @@ main(int argc, char *argv[])
                 case 's':
                         salt = optarg;
                         break;
+		case 'q':
+			quiet++;
+			break;
 		case 'x':
 			hex_output++;
 			break;
@@ -257,7 +264,7 @@ main(int argc, char *argv[])
 	passhash = xmalloc(2*hashlen + 2);
 
 	/* try to lock memory so it doesn't get swapped out for sure */
-	if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
+	if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1 && !quiet) {
 		perror("mlockall");
 		fputs("Warning: couldn't lock memory, are you root?\n", stderr);
 	}
--- hashalot-0.3.orig/sha512.c
+++ hashalot-0.3/sha512.c
@@ -4,7 +4,7 @@
  *  Written by Jari Ruusu, April 16 2001
  *
  *  Copyright 2001 by Jari Ruusu.
- *  Redistribution of this file is permitted under the GNU Public License.
+ *  Redistribution of this file is permitted under the GNU General Public License.
  */
 
 #include <string.h>
--- hashalot-0.3.orig/sha512.h
+++ hashalot-0.3/sha512.h
@@ -4,7 +4,7 @@
  *  Written by Jari Ruusu, April 16 2001
  *
  *  Copyright 2001 by Jari Ruusu.
- *  Redistribution of this file is permitted under the GNU Public License.
+ *  Redistribution of this file is permitted under the GNU General Public License.
  */
 
 #include <sys/types.h>