summaryrefslogtreecommitdiffstats
path: root/third_party/fips181
diff options
context:
space:
mode:
authorgcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-10 18:07:47 +0000
committergcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-10 18:07:47 +0000
commit429674f71712fc48ca5e59d20f7c1ee796c1e5e8 (patch)
treec2fb03bd5303aa1f6c98e9d5207f33d2f981d0d7 /third_party/fips181
parent7c444a0cee58b54f0bd3234f0564d67158c2d901 (diff)
downloadchromium_src-429674f71712fc48ca5e59d20f7c1ee796c1e5e8.zip
chromium_src-429674f71712fc48ca5e59d20f7c1ee796c1e5e8.tar.gz
chromium_src-429674f71712fc48ca5e59d20f7c1ee796c1e5e8.tar.bz2
[Password Generation] Start using pronouncable passwords
BUG=165318 Review URL: https://codereview.chromium.org/308503002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276081 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/fips181')
-rw-r--r--third_party/fips181/convert.cc27
-rw-r--r--third_party/fips181/fips181.cc50
-rw-r--r--third_party/fips181/fips181.h16
-rw-r--r--third_party/fips181/randpass.cc15
-rw-r--r--third_party/fips181/randpass.h10
-rw-r--r--third_party/fips181/smbl.h3
6 files changed, 43 insertions, 78 deletions
diff --git a/third_party/fips181/convert.cc b/third_party/fips181/convert.cc
index 9b4ef85..00af6a8 100644
--- a/third_party/fips181/convert.cc
+++ b/third_party/fips181/convert.cc
@@ -33,10 +33,11 @@
#include <strings.h>
#endif
#ifndef APGBFM
-# include "errs.h"
-# include "randpass.h"
+#include "fips181.h"
+#include "randpass.h"
#endif
+#include "base/rand_util.h"
#include "convert.h"
/*
@@ -77,7 +78,7 @@ decapitalize (char *word)
{
int i = 0; /* counter */
int j = 0; /* counter */
- int str_len = strlen(word);
+ int str_len = (int) strlen(word);
for(j = 0; j < str_len; j++)
for(i=0; i < 26; i++)
if(word[j] == clet[i])
@@ -102,7 +103,7 @@ capitalize (char *syllable)
{
char tmp = 0x00;
int i = 0;
- if ( randint(2) == TRUE)
+ if (base::RandInt(0, 1) == 1)
{
(void)memcpy((void *)&tmp, (void *)syllable, sizeof(tmp));
for(i=0; i < 26; i++)
@@ -128,9 +129,7 @@ capitalize (char *syllable)
void
numerize (char *syllable)
{
- char *tmp;
- if ( (tmp = (char *)calloc(1, 4)) == NULL)
- err_sys_fatal("calloc");
+ char *tmp = (char *)calloc(1, 4);
if ( strlen (syllable) == 1 )
{
(void) gen_rand_symbol(tmp, S_NB);
@@ -154,9 +153,7 @@ numerize (char *syllable)
void
specialize (char *syllable)
{
- char *tmp;
- if ( (tmp = (char *)calloc(1, 4)) == NULL)
- err_sys_fatal("calloc");
+ char *tmp = (char *)calloc(1, 4);
if ( strlen (syllable) == 1 )
{
(void) gen_rand_symbol(tmp, S_SS);
@@ -180,9 +177,9 @@ symb2name(char * syllable, char * h_syllable)
struct ssymb_names
{
char symbol;
- char *name;
+ const char * name;
};
- static struct ssymb_names ssn[42] =
+ static const struct ssymb_names ssn[42] =
{
{'1',"ONE"},
{'2',"TWO"},
@@ -262,7 +259,7 @@ spell_word(char * word, char * spelled_word)
struct char_spell
{
char symbol;
- char *name;
+ const char *name;
};
static struct char_spell cs[94] =
{
@@ -364,7 +361,7 @@ spell_word(char * word, char * spelled_word)
int s_length = 0;
int i = 0;
int j = 0;
- int word_len = strlen(word);
+ int word_len = (int) strlen(word);
char * tmp_ptr;
char hyphen = '-';
char zero = 0x00;
@@ -374,7 +371,7 @@ spell_word(char * word, char * spelled_word)
for (j=0; j < 94; j++)
if (word[i] == cs[j].symbol)
{
- s_length = s_length + strlen(cs[j].name) + 1;
+ s_length = s_length + (int) strlen(cs[j].name) + 1;
continue;
}
diff --git a/third_party/fips181/fips181.cc b/third_party/fips181/fips181.cc
index ca78293..a7725cb 100644
--- a/third_party/fips181/fips181.cc
+++ b/third_party/fips181/fips181.cc
@@ -42,10 +42,10 @@
#endif
#include <time.h>
#include <sys/types.h>
-#include "pronpass.h"
+#include "base/rand_util.h"
+#include "fips181.h"
#include "randpass.h"
#include "convert.h"
-#include "errs.h"
struct unit
{
@@ -1293,7 +1293,8 @@ gen_pron_pass (char *word, char *hyphenated_word, USHORT minlen,
/*
* Find password.
*/
- pwlen = gen_word (word, hyphenated_word, get_random (minlen, maxlen), pass_mode);
+ pwlen = gen_word (word, hyphenated_word, base::RandInt(minlen, maxlen),
+ pass_mode);
return (pwlen);
}
@@ -1364,7 +1365,7 @@ gen_word (char *word, char *hyphenated_word, USHORT pwlen, unsigned int pass_mod
* Get the syllable and find its length.
*/
(void) gen_syllable (new_syllable, pwlen - word_length, syllable_units, &syllable_size);
- syllable_length = strlen (new_syllable);
+ syllable_length = (USHORT) strlen (new_syllable);
/*
* Append the syllable units to the word units.
@@ -1394,7 +1395,7 @@ gen_word (char *word, char *hyphenated_word, USHORT pwlen, unsigned int pass_mod
** Modify syllable for numeric or capital symbols required
** Should be done after word quality check.
*/
- dsd = randint(2);
+ dsd = base::RandInt(0, 1);
if ( ((pass_mode & S_NB) > 0) && (syllable_length == 1) && dsd == 0)
{
numerize(new_syllable);
@@ -1428,7 +1429,7 @@ gen_word (char *word, char *hyphenated_word, USHORT pwlen, unsigned int pass_mod
** Modify syllable for numeric or capital symbols required
** Should be done after word quality check.
*/
- dsd = randint(2);
+ dsd = base::RandInt(0, 1);
if ( ((pass_mode & S_NB) > 0) && (syllable_length == 1) && (dsd == 0))
{
numerize(new_syllable);
@@ -1734,7 +1735,7 @@ gen_syllable (char *syllable, USHORT pwlen, USHORT *units_in_syllable,
vowel_count++;
current_unit++;
(void) strcpy (syllable, rules[saved_pair[1]].unit_code);
- length_left -= strlen (syllable);
+ length_left -= (short) strlen (syllable);
}
/*
@@ -2249,42 +2250,19 @@ random_unit (USHORT type)
{
USHORT number;
- /*
+ /*
* Sometimes, we are asked to explicitly get a vowel (i.e., if
* a digram pair expects one following it). This is a shortcut
* to do that and avoid looping with rejected consonants.
*/
if (type & VOWEL)
- number = vowel_numbers[get_random (0, (sizeof (vowel_numbers) / sizeof (USHORT))-1)];
+ number = vowel_numbers[
+ base::RandInt(0, (sizeof (vowel_numbers) / sizeof (USHORT))-1)];
else
- /*
+ /*
* Get any letter according to the English distribution.
*/
- number = numbers[get_random (0, (sizeof (numbers) / sizeof (USHORT))-1)];
+ number = numbers[
+ base::RandInt(0, (sizeof (numbers) / sizeof (USHORT))-1)];
return (number);
}
-
-
-/*
-** get_random() -
-** This routine should return a uniformly distributed Random number between
-** minlen and maxlen inclusive. The Electronic Code Book form of CAST is
-** used to produce the Random number. The inputs to CAST are the old pass-
-** word and a pseudoRandom key generated according to the procedure out-
-** lined in Appendix C of ANSI X9.17.
-** INPUT:
-** USHORT - minimum
-** USHORT - maximum
-** OUTPUT:
-** USHORT - random number
-** NOTES:
-** none.
-*/
-
-USHORT
-get_random (USHORT minlen, USHORT maxlen)
-{
- USHORT ret = 0;
- ret = minlen + (USHORT) randint ((int) (maxlen - minlen + 1));
- return (ret);
-}
diff --git a/third_party/fips181/fips181.h b/third_party/fips181/fips181.h
index bc9270b..524da59 100644
--- a/third_party/fips181/fips181.h
+++ b/third_party/fips181/fips181.h
@@ -41,10 +41,6 @@
#include "owntypes.h"
#endif /* APG_OWN_TYPES_H */
-#ifndef APG_RND_H
-#include "rnd.h"
-#endif /* APG_RND_H */
-
#define RULE_SIZE (sizeof(rules)/sizeof(struct unit))
#define ALLOWED(flag) (digram[units_in_syllable[current_unit -1]][unit] & (flag))
@@ -67,17 +63,21 @@
#define NOT_END 01
#define ANY_COMBINATION 0
-extern int gen_pron_pass (char *word, char *hyphenated_word, USHORT minlen,
- USHORT maxlen, unsigned int pass_mode);
+#define S_NB 0x01 /* Numeric */
+#define S_SS 0x02 /* Special */
+#define S_CL 0x04 /* Capital */
+#define S_SL 0x08 /* Small */
+#define S_RS 0x10 /* Restricted Symbol*/
+extern int gen_pron_pass (char *word, char* hypenated_word,
+ USHORT minlen, USHORT maxlen, unsigned int pass_mode);
USHORT random_unit (USHORT type);
USHORT get_random (USHORT minlen, USHORT maxlen);
boolean have_initial_y (USHORT *units, USHORT unit_size);
boolean illegal_placement (USHORT *units, USHORT pwlen);
boolean improper_word (USHORT *units, USHORT word_size);
boolean have_final_split (USHORT *units, USHORT unit_size);
-int gen_word (char *word, char *hyphenated_word, USHORT pwlen,
- unsigned int pass_mode);
+int gen_word (char *word, char *hyphenated_word, USHORT pwlen, unsigned int pass_mode);
char *gen_syllable(char *syllable, USHORT pwlen, USHORT *units_in_syllable,
USHORT *syllable_length);
diff --git a/third_party/fips181/randpass.cc b/third_party/fips181/randpass.cc
index b804365..8aded15 100644
--- a/third_party/fips181/randpass.cc
+++ b/third_party/fips181/randpass.cc
@@ -34,13 +34,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32__)
-#include <pwd.h>
-#endif
-#include <unistd.h>
-#include "randpass.h"
+#include "base/rand_util.h"
#include "owntypes.h"
+#include "randpass.h"
#include "smbl.h"
/*
@@ -69,8 +66,8 @@ gen_rand_pass (char *password_string, int minl, int maxl, unsigned int pass_mode
if (minl > APG_MAX_PASSWORD_LENGTH || maxl > APG_MAX_PASSWORD_LENGTH ||
minl < 1 || maxl < 1 || minl > maxl)
return (-1);
- for (i = 0; i <= 93; i++) random_weight[i] = 0;
- length = minl + randint(maxl-minl+1);
+ for (i = 0; i <= 93; i++) random_weight[i] = 0;
+ length = base::RandInt(minl, maxl);
str_pointer = password_string;
for (i = 0; i < length; i++)
@@ -79,7 +76,7 @@ gen_rand_pass (char *password_string, int minl, int maxl, unsigned int pass_mode
for (j = 0; j <= 93 ; j++)
if ( ( (pass_mode & smbl[j].type) > 0) &&
!( (S_RS & smbl[j].type) > 0))
- random_weight[j] = 1 + randint(20000);
+ random_weight[j] = base::RandInt(1, 20000);
j = 0;
/* Find an element with maximum weight */
for (j = 0; j <= 93; j++)
@@ -125,7 +122,7 @@ gen_rand_symbol (char *symbol, unsigned int mode)
for (j = 0; j <= 93 ; j++)
if ( ( (mode & smbl[j].type) > 0) &&
!( (S_RS & smbl[j].type) > 0))
- random_weight[j] = 1 + randint(20000);
+ random_weight[j] = base::RandInt(1, 20000);
j = 0;
/* Find an element with maximum weight */
for (j = 0; j <= 93; j++)
diff --git a/third_party/fips181/randpass.h b/third_party/fips181/randpass.h
index dbe1da4..ee0df62 100644
--- a/third_party/fips181/randpass.h
+++ b/third_party/fips181/randpass.h
@@ -33,20 +33,10 @@
#ifndef APG_RANDPASS_H
#define APG_RANDPASS_H 1
-#ifndef APG_RND_H
-#include "rnd.h"
-#endif
-
#ifndef APG_OWN_TYPES_H
#include "owntypes.h"
#endif
-#define S_NB 0x01 /* Numeric */
-#define S_SS 0x02 /* Special */
-#define S_CL 0x04 /* Capital */
-#define S_SL 0x08 /* Small */
-#define S_RS 0x10 /* Restricted Symbol*/
-
struct sym
{
char ch;
diff --git a/third_party/fips181/smbl.h b/third_party/fips181/smbl.h
index bb94ef5..9b63ed9 100644
--- a/third_party/fips181/smbl.h
+++ b/third_party/fips181/smbl.h
@@ -28,6 +28,9 @@
*/
#ifndef APG_SMBL_H
#define APG_SMBL_H 1
+
+#include "fips181.h"
+
struct sym smbl[94] =
{
{'a', S_SL}, {'b', S_SL}, {'c', S_SL}, {'d', S_SL}, {'e', S_SL}, {'f', S_SL},