Commit b81844b1 authored by Bruce Momjian's avatar Bruce Momjian

pgindent run on all C files. Java run to follow. initdb/regression

tests pass.
parent 59da2105
...@@ -34,7 +34,6 @@ int32 array_all_int4le(ArrayType *array, int4 value); ...@@ -34,7 +34,6 @@ int32 array_all_int4le(ArrayType *array, int4 value);
int32 array_oideq(ArrayType *array, Oid value); int32 array_oideq(ArrayType *array, Oid value);
int32 array_all_oidne(ArrayType *array, Oid value); int32 array_all_oidne(ArrayType *array, Oid value);
#endif #endif
/* /*
......
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* darcy@druid.net * darcy@druid.net
* http://www.druid.net/darcy/ * http://www.druid.net/darcy/
* *
* $Id: chkpass.c,v 1.4 2001/05/30 02:11:46 darcy Exp $ * $Id: chkpass.c,v 1.5 2001/10/25 05:49:19 momjian Exp $
* best viewed with tabs set to 4 * best viewed with tabs set to 4
*/ */
...@@ -166,10 +166,11 @@ chkpass_eq(PG_FUNCTION_ARGS) ...@@ -166,10 +166,11 @@ chkpass_eq(PG_FUNCTION_ARGS)
if (!a1 || !a2) if (!a1 || !a2)
PG_RETURN_BOOL(0); PG_RETURN_BOOL(0);
if (a2->vl_len < 12) sz = a2->vl_len - 4; if (a2->vl_len < 12)
sz = a2->vl_len - 4;
strncpy(str, a2->vl_dat, sz); strncpy(str, a2->vl_dat, sz);
str[sz] = 0; str[sz] = 0;
PG_RETURN_BOOL (strcmp(a1->password, crypt(str, a1->password)) == 0); PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) == 0);
} }
PG_FUNCTION_INFO_V1(chkpass_ne) PG_FUNCTION_INFO_V1(chkpass_ne)
...@@ -181,10 +182,11 @@ chkpass_ne(PG_FUNCTION_ARGS) ...@@ -181,10 +182,11 @@ chkpass_ne(PG_FUNCTION_ARGS)
char str[10]; char str[10];
int sz = 8; int sz = 8;
if (!a1 || !a2) PG_RETURN_BOOL(0); if (!a1 || !a2)
if (a2->vl_len < 12) sz = a2->vl_len - 4; PG_RETURN_BOOL(0);
if (a2->vl_len < 12)
sz = a2->vl_len - 4;
strncpy(str, a2->vl_dat, sz); strncpy(str, a2->vl_dat, sz);
str[sz] = 0; str[sz] = 0;
PG_RETURN_BOOL (strcmp(a1->password, crypt(str, a1->password)) != 0); PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) != 0);
} }
...@@ -166,7 +166,6 @@ g_cube_consistent(GISTENTRY *entry, ...@@ -166,7 +166,6 @@ g_cube_consistent(GISTENTRY *entry,
NDBOX * query, NDBOX * query,
StrategyNumber strategy) StrategyNumber strategy)
{ {
/* /*
* if entry is not leaf, use g_cube_internal_consistent, else use * if entry is not leaf, use g_cube_internal_consistent, else use
* g_cube_leaf_consistent * g_cube_leaf_consistent
...@@ -365,7 +364,6 @@ g_cube_picksplit(bytea *entryvec, ...@@ -365,7 +364,6 @@ g_cube_picksplit(bytea *entryvec,
maxoff = OffsetNumberNext(maxoff); maxoff = OffsetNumberNext(maxoff);
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{ {
/* /*
* If we've already decided where to place this item, just put it * If we've already decided where to place this item, just put it
* on the right list. Otherwise, we need to figure out which page * on the right list. Otherwise, we need to figure out which page
...@@ -1001,7 +999,6 @@ cube_contains(NDBOX * box_a, NDBOX * box_b) ...@@ -1001,7 +999,6 @@ cube_contains(NDBOX * box_a, NDBOX * box_b)
if (a->dim < b->dim) if (a->dim < b->dim)
{ {
/* /*
* the further comparisons will make sense if the excess * the further comparisons will make sense if the excess
* dimensions of (b) were zeroes * dimensions of (b) were zeroes
......
This diff is collapsed.
...@@ -41,7 +41,8 @@ ...@@ -41,7 +41,8 @@
/* diskheader */ /* diskheader */
typedef struct { typedef struct
{
u_char dbh_dbt; /* indentification field */ u_char dbh_dbt; /* indentification field */
u_char dbh_year; /* last modification-date */ u_char dbh_year; /* last modification-date */
u_char dbh_month; u_char dbh_month;
...@@ -54,19 +55,21 @@ typedef struct { ...@@ -54,19 +55,21 @@ typedef struct {
/* disk field-description */ /* disk field-description */
typedef struct { typedef struct
{
u_char dbf_name[DBF_NAMELEN]; /* field-name terminated with \0 */ u_char dbf_name[DBF_NAMELEN]; /* field-name terminated with \0 */
u_char dbf_type; /* field-type */ u_char dbf_type; /* field-type */
u_char dbf_reserved[4]; /* some reserved stuff */ u_char dbf_reserved[4]; /* some reserved stuff */
u_char dbf_flen; /* field-length */ u_char dbf_flen; /* field-length */
u_char dbf_dec; /* number of decimal positions if u_char dbf_dec; /* number of decimal positions if type is
type is 'N' */ * 'N' */
u_char dbf_stub[14]; /* stuff we don't need */ u_char dbf_stub[14]; /* stuff we don't need */
} dbf_field; } dbf_field;
/* memory field-description */ /* memory field-description */
typedef struct { typedef struct
{
u_char db_name[DBF_NAMELEN]; /* field-name terminated with \0 */ u_char db_name[DBF_NAMELEN]; /* field-name terminated with \0 */
u_char db_type; /* field-type */ u_char db_type; /* field-type */
u_char db_flen; /* field-length */ u_char db_flen; /* field-length */
...@@ -75,7 +78,8 @@ typedef struct { ...@@ -75,7 +78,8 @@ typedef struct {
/* memory dfb-header */ /* memory dfb-header */
typedef struct { typedef struct
{
int db_fd; /* file-descriptor */ int db_fd; /* file-descriptor */
u_long db_offset; /* current offset in file */ u_long db_offset; /* current offset in file */
u_char db_memo; /* memo-file present */ u_char db_memo; /* memo-file present */
...@@ -83,15 +87,14 @@ typedef struct { ...@@ -83,15 +87,14 @@ typedef struct {
u_char db_month; u_char db_month;
u_char db_day; u_char db_day;
u_long db_hlen; /* length of the diskheader, for u_long db_hlen; /* length of the diskheader, for
calculating the offsets */ * calculating the offsets */
u_long db_records; /* number of records */ u_long db_records; /* number of records */
u_long db_currec; /* current record-number starting u_long db_currec; /* current record-number starting at 0 */
at 0 */
u_short db_rlen; /* length of the record */ u_short db_rlen; /* length of the record */
u_char db_nfields; /* number of fields */ u_char db_nfields; /* number of fields */
u_char *db_buff; /* record-buffer to save malloc()'s */ u_char *db_buff; /* record-buffer to save malloc()'s */
f_descr *db_fields; /* pointer to an array of field- f_descr *db_fields; /* pointer to an array of field-
descriptions */ * descriptions */
} dbhead; } dbhead;
/* structure that contains everything a user wants from a field, including /* structure that contains everything a user wants from a field, including
...@@ -99,27 +102,28 @@ typedef struct { ...@@ -99,27 +102,28 @@ typedef struct {
length of db_name! This is because a field doesn't have to be completely length of db_name! This is because a field doesn't have to be completely
filled */ filled */
typedef struct { typedef struct
{
u_char db_name[DBF_NAMELEN]; /* field-name terminated with \0 */ u_char db_name[DBF_NAMELEN]; /* field-name terminated with \0 */
u_char db_type; /* field-type */ u_char db_type; /* field-type */
u_char db_flen; /* field-length */ u_char db_flen; /* field-length */
u_char db_dec; /* number of decimal positions */ u_char db_dec; /* number of decimal positions */
u_char* db_contents; /* contents of the field in ASCII */ u_char *db_contents; /* contents of the field in ASCII */
} field; } field;
/* prototypes for functions */ /* prototypes for functions */
extern dbhead* dbf_open(u_char *file ,int flags); extern dbhead *dbf_open(u_char *file, int flags);
extern int dbf_write_head(dbhead *dbh); extern int dbf_write_head(dbhead * dbh);
extern int dbf_put_fields(dbhead *dbh); extern int dbf_put_fields(dbhead * dbh);
extern int dbf_add_field(dbhead *dbh, u_char *name, u_char type, extern int dbf_add_field(dbhead * dbh, u_char *name, u_char type,
u_char length, u_char dec); u_char length, u_char dec);
extern dbhead * dbf_open_new(u_char *name, int flags); extern dbhead *dbf_open_new(u_char *name, int flags);
extern void dbf_close(dbhead *dbh); extern void dbf_close(dbhead * dbh);
extern int dbf_get_record(dbhead *dbh, field *fields, u_long rec); extern int dbf_get_record(dbhead * dbh, field * fields, u_long rec);
extern field* dbf_build_record(dbhead *dbh); extern field *dbf_build_record(dbhead * dbh);
extern void dbf_free_record(dbhead *dbh, field* fields); extern void dbf_free_record(dbhead * dbh, field * fields);
extern int dbf_put_record(dbhead *dbh, field *rec, u_long where); extern int dbf_put_record(dbhead * dbh, field * rec, u_long where);
/********************************************************************* /*********************************************************************
...@@ -131,5 +135,4 @@ extern long get_long(u_char *cp); ...@@ -131,5 +135,4 @@ extern long get_long(u_char *cp);
extern void put_long(u_char *cp, long lval); extern void put_long(u_char *cp, long lval);
extern short get_short(u_char *cp); extern short get_short(u_char *cp);
extern void put_short(u_char *cp, short lval); extern void put_short(u_char *cp, short lval);
#endif /* _DBF_H */ #endif /* _DBF_H */
This diff is collapsed.
...@@ -5,19 +5,21 @@ ...@@ -5,19 +5,21 @@
/* /*
* routine to change little endian long to host long * routine to change little endian long to host long
*/ */
long get_long(u_char *cp) long
get_long(u_char *cp)
{ {
long ret; long ret;
ret = *cp++; ret = *cp++;
ret += ((*cp++)<<8); ret += ((*cp++) << 8);
ret += ((*cp++)<<16); ret += ((*cp++) << 16);
ret += ((*cp++)<<24); ret += ((*cp++) << 24);
return ret; return ret;
} }
void put_long(u_char *cp, long lval) void
put_long(u_char *cp, long lval)
{ {
cp[0] = lval & 0xff; cp[0] = lval & 0xff;
cp[1] = (lval >> 8) & 0xff; cp[1] = (lval >> 8) & 0xff;
...@@ -28,17 +30,19 @@ void put_long(u_char *cp, long lval) ...@@ -28,17 +30,19 @@ void put_long(u_char *cp, long lval)
/* /*
* routine to change little endian short to host short * routine to change little endian short to host short
*/ */
short get_short(u_char *cp) short
get_short(u_char *cp)
{ {
short ret; short ret;
ret = *cp++; ret = *cp++;
ret += ((*cp++)<<8); ret += ((*cp++) << 8);
return ret; return ret;
} }
void put_short(u_char *cp, short sval) void
put_short(u_char *cp, short sval)
{ {
cp[0] = sval & 0xff; cp[0] = sval & 0xff;
cp[1] = (sval >> 8) & 0xff; cp[1] = (sval >> 8) & 0xff;
......
...@@ -41,18 +41,17 @@ dblink(PG_FUNCTION_ARGS) ...@@ -41,18 +41,17 @@ dblink(PG_FUNCTION_ARGS)
int ntuples = 0; int ntuples = 0;
ReturnSetInfo *rsi; ReturnSetInfo *rsi;
if (PG_ARGISNULL(0) || PG_ARGISNULL(1)) { if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
elog(ERROR, "dblink: NULL arguments are not permitted"); elog(ERROR, "dblink: NULL arguments are not permitted");
}
if (fcinfo->resultinfo == NULL || ! IsA(fcinfo->resultinfo, ReturnSetInfo)) { if (fcinfo->resultinfo == NULL || !IsA(fcinfo->resultinfo, ReturnSetInfo))
elog(ERROR, "dblink: function called in context that does not accept a set result"); elog(ERROR, "dblink: function called in context that does not accept a set result");
}
optstr = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(0)))); optstr = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(0))));
sqlstatement = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(1)))); sqlstatement = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(1))));
if (fcinfo->flinfo->fn_extra == NULL) { if (fcinfo->flinfo->fn_extra == NULL)
{
conn = PQconnectdb(optstr); conn = PQconnectdb(optstr);
if (PQstatus(conn) == CONNECTION_BAD) if (PQstatus(conn) == CONNECTION_BAD)
...@@ -73,13 +72,14 @@ dblink(PG_FUNCTION_ARGS) ...@@ -73,13 +72,14 @@ dblink(PG_FUNCTION_ARGS)
PQclear(res); PQclear(res);
execstatement = (char *) palloc(strlen(curstr) + strlen(sqlstatement) + 1); execstatement = (char *) palloc(strlen(curstr) + strlen(sqlstatement) + 1);
if (execstatement != NULL) { if (execstatement != NULL)
{
strcpy(execstatement, curstr); strcpy(execstatement, curstr);
strcat(execstatement, sqlstatement); strcat(execstatement, sqlstatement);
strcat(execstatement, "\0"); strcat(execstatement, "\0");
} else {
elog(ERROR, "dblink: insufficient memory" );
} }
else
elog(ERROR, "dblink: insufficient memory");
res = PQexec(conn, execstatement); res = PQexec(conn, execstatement);
if (!res || (PQresultStatus(res) != PGRES_COMMAND_OK && PQresultStatus(res) != PGRES_TUPLES_OK)) if (!res || (PQresultStatus(res) != PGRES_COMMAND_OK && PQresultStatus(res) != PGRES_TUPLES_OK))
...@@ -88,14 +88,17 @@ dblink(PG_FUNCTION_ARGS) ...@@ -88,14 +88,17 @@ dblink(PG_FUNCTION_ARGS)
PQclear(res); PQclear(res);
PQfinish(conn); PQfinish(conn);
elog(ERROR, "dblink: sql error: %s", msg); elog(ERROR, "dblink: sql error: %s", msg);
} else { }
else
{
/* /*
* got results, start fetching them * got results, start fetching them
*/ */
PQclear(res); PQclear(res);
res = PQexec(conn, "FETCH ALL in mycursor"); res = PQexec(conn, "FETCH ALL in mycursor");
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) { if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
{
msg = pstrdup(PQerrorMessage(conn)); msg = pstrdup(PQerrorMessage(conn));
PQclear(res); PQclear(res);
PQfinish(conn); PQfinish(conn);
...@@ -104,7 +107,8 @@ dblink(PG_FUNCTION_ARGS) ...@@ -104,7 +107,8 @@ dblink(PG_FUNCTION_ARGS)
ntuples = PQntuples(res); ntuples = PQntuples(res);
if (ntuples > 0) { if (ntuples > 0)
{
results = init_dblink_results(fcinfo->flinfo->fn_mcxt); results = init_dblink_results(fcinfo->flinfo->fn_mcxt);
results->tup_num = 0; results->tup_num = 0;
...@@ -127,12 +131,14 @@ dblink(PG_FUNCTION_ARGS) ...@@ -127,12 +131,14 @@ dblink(PG_FUNCTION_ARGS)
/* close the connection to the database and cleanup */ /* close the connection to the database and cleanup */
PQfinish(conn); PQfinish(conn);
rsi = (ReturnSetInfo *)fcinfo->resultinfo; rsi = (ReturnSetInfo *) fcinfo->resultinfo;
rsi->isDone = ExprMultipleResult; rsi->isDone = ExprMultipleResult;
PG_RETURN_POINTER(results); PG_RETURN_POINTER(results);
} else { }
else
{
PQclear(res); PQclear(res);
...@@ -147,13 +153,15 @@ dblink(PG_FUNCTION_ARGS) ...@@ -147,13 +153,15 @@ dblink(PG_FUNCTION_ARGS)
/* close the connection to the database and cleanup */ /* close the connection to the database and cleanup */
PQfinish(conn); PQfinish(conn);
rsi = (ReturnSetInfo *)fcinfo->resultinfo; rsi = (ReturnSetInfo *) fcinfo->resultinfo;
rsi->isDone = ExprEndResult ; rsi->isDone = ExprEndResult;
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
} }
} else { }
else
{
/* /*
* check for more results * check for more results
*/ */
...@@ -162,19 +170,20 @@ dblink(PG_FUNCTION_ARGS) ...@@ -162,19 +170,20 @@ dblink(PG_FUNCTION_ARGS)
results->tup_num++; results->tup_num++;
ntuples = PQntuples(results->res); ntuples = PQntuples(results->res);
if (results->tup_num < ntuples) { if (results->tup_num < ntuples)
{
/* /*
* fetch them if available * fetch them if available
*/ */
rsi = (ReturnSetInfo *)fcinfo->resultinfo; rsi = (ReturnSetInfo *) fcinfo->resultinfo;
rsi->isDone = ExprMultipleResult; rsi->isDone = ExprMultipleResult;
PG_RETURN_POINTER(results); PG_RETURN_POINTER(results);
} else { }
else
{
/* /*
* or if no more, clean things up * or if no more, clean things up
*/ */
...@@ -183,8 +192,8 @@ dblink(PG_FUNCTION_ARGS) ...@@ -183,8 +192,8 @@ dblink(PG_FUNCTION_ARGS)
PQclear(results->res); PQclear(results->res);
rsi = (ReturnSetInfo *)fcinfo->resultinfo; rsi = (ReturnSetInfo *) fcinfo->resultinfo;
rsi->isDone = ExprEndResult ; rsi->isDone = ExprEndResult;
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -211,41 +220,41 @@ dblink_tok(PG_FUNCTION_ARGS) ...@@ -211,41 +220,41 @@ dblink_tok(PG_FUNCTION_ARGS)
int nfields = 0; int nfields = 0;
int text_len = 0; int text_len = 0;
if (PG_ARGISNULL(0) || PG_ARGISNULL(1)) { if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
elog(ERROR, "dblink: NULL arguments are not permitted"); elog(ERROR, "dblink: NULL arguments are not permitted");
}
results = (dblink_results *) PG_GETARG_POINTER(0); results = (dblink_results *) PG_GETARG_POINTER(0);
if (results == NULL) { if (results == NULL)
elog(ERROR, "dblink: function called with invalid result pointer"); elog(ERROR, "dblink: function called with invalid result pointer");
}
fldnum = PG_GETARG_INT32(1); fldnum = PG_GETARG_INT32(1);
if (fldnum < 0) { if (fldnum < 0)
elog(ERROR, "dblink: field number < 0 not permitted"); elog(ERROR, "dblink: field number < 0 not permitted");
}
nfields = PQnfields(results->res); nfields = PQnfields(results->res);
if (fldnum > (nfields - 1)) { if (fldnum > (nfields - 1))
elog(ERROR, "dblink: field number %d does not exist", fldnum); elog(ERROR, "dblink: field number %d does not exist", fldnum);
}
if (PQgetisnull(results->res, results->tup_num, fldnum) == 1) { if (PQgetisnull(results->res, results->tup_num, fldnum) == 1)
{
PG_RETURN_NULL(); PG_RETURN_NULL();
} else { }
else
{
text_len = PQgetlength(results->res, results->tup_num, fldnum); text_len = PQgetlength(results->res, results->tup_num, fldnum);
result = (char *) palloc(text_len + 1); result = (char *) palloc(text_len + 1);
if (result != NULL) { if (result != NULL)
{
strcpy(result, PQgetvalue(results->res, results->tup_num, fldnum)); strcpy(result, PQgetvalue(results->res, results->tup_num, fldnum));
strcat(result, "\0"); strcat(result, "\0");
} else {
elog(ERROR, "dblink: insufficient memory" );
} }
else
elog(ERROR, "dblink: insufficient memory");
result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(result))); result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(result)));
......
...@@ -66,5 +66,4 @@ extern Datum dblink_tok(PG_FUNCTION_ARGS); ...@@ -66,5 +66,4 @@ extern Datum dblink_tok(PG_FUNCTION_ARGS);
* Internal declarations * Internal declarations
*/ */
dblink_results *init_dblink_results(MemoryContext fn_mcxt); dblink_results *init_dblink_results(MemoryContext fn_mcxt);
#endif /* DBLINK_H */ #endif /* DBLINK_H */
...@@ -103,7 +103,6 @@ char *StopWords[] = { /* list of words to skip in indexing */ ...@@ -103,7 +103,6 @@ char *StopWords[] = { /* list of words to skip in indexing */
"the", "the",
"yes" "yes"
}; };
#endif /* USE_STOP_WORDS */ #endif /* USE_STOP_WORDS */
/* stuff for caching query-plans, stolen from contrib/spi/\*.c */ /* stuff for caching query-plans, stolen from contrib/spi/\*.c */
...@@ -205,9 +204,7 @@ fti(PG_FUNCTION_ARGS) ...@@ -205,9 +204,7 @@ fti(PG_FUNCTION_ARGS)
snprintf(query, MAX_FTI_QUERY_LENGTH, "D%s", indexname); snprintf(query, MAX_FTI_QUERY_LENGTH, "D%s", indexname);
for (i = 1; i < nargs; i++) for (i = 1; i < nargs; i++)
{
snprintf(query, MAX_FTI_QUERY_LENGTH, "%s$%s", query, args[i]); snprintf(query, MAX_FTI_QUERY_LENGTH, "%s$%s", query, args[i]);
}
plan = find_plan(query, &DeletePlans, &nDeletePlans); plan = find_plan(query, &DeletePlans, &nDeletePlans);
if (plan->nplans <= 0) if (plan->nplans <= 0)
...@@ -252,9 +249,7 @@ fti(PG_FUNCTION_ARGS) ...@@ -252,9 +249,7 @@ fti(PG_FUNCTION_ARGS)
snprintf(query, MAX_FTI_QUERY_LENGTH, "I%s", indexname); snprintf(query, MAX_FTI_QUERY_LENGTH, "I%s", indexname);
for (i = 1; i < nargs; i++) for (i = 1; i < nargs; i++)
{
snprintf(query, MAX_FTI_QUERY_LENGTH, "%s$%s", query, args[i]); snprintf(query, MAX_FTI_QUERY_LENGTH, "%s$%s", query, args[i]);
}
plan = find_plan(query, &InsertPlans, &nInsertPlans); plan = find_plan(query, &InsertPlans, &nInsertPlans);
...@@ -303,7 +298,7 @@ fti(PG_FUNCTION_ARGS) ...@@ -303,7 +298,7 @@ fti(PG_FUNCTION_ARGS)
string++; string++;
} }
data = (struct varlena *) palloc(sizeof(int32) + strlen(column) + 1); data = (struct varlena *) palloc(sizeof(int32) + strlen(column) +1);
buff = palloc(strlen(column) + 1); buff = palloc(strlen(column) + 1);
/* saves lots of calls in while-loop and in breakup() */ /* saves lots of calls in while-loop and in breakup() */
...@@ -348,7 +343,6 @@ breakup(char *string, char *substring) ...@@ -348,7 +343,6 @@ breakup(char *string, char *substring)
while (cur_pos > string) /* don't read before start of 'string' */ while (cur_pos > string) /* don't read before start of 'string' */
{ {
/* /*
* skip pieces at the end of a string that are not alfa-numeric * skip pieces at the end of a string that are not alfa-numeric
* (ie. 'string$%^&', last_start first points to '&', and after * (ie. 'string$%^&', last_start first points to '&', and after
......
This diff is collapsed.
...@@ -132,13 +132,14 @@ static const char *soundex_table = "01230120022455012623010202"; ...@@ -132,13 +132,14 @@ static const char *soundex_table = "01230120022455012623010202";
#define SH 'X' #define SH 'X'
#define TH '0' #define TH '0'
char Lookahead(char * word, int how_far); char Lookahead(char *word, int how_far);
int _metaphone ( int
_metaphone(
/* IN */ /* IN */
char * word, char *word,
int max_phonemes, int max_phonemes,
/* OUT */ /* OUT */
char ** phoned_word char **phoned_word
); );
/* Metachar.h ... little bits about characters for metaphone */ /* Metachar.h ... little bits about characters for metaphone */
...@@ -147,7 +148,7 @@ int _metaphone ( ...@@ -147,7 +148,7 @@ int _metaphone (
/*-- Character encoding array & accessing macros --*/ /*-- Character encoding array & accessing macros --*/
/* Stolen directly out of the book... */ /* Stolen directly out of the book... */
char _codes[26] = { char _codes[26] = {
1,16,4,16,9,2,4,16,9,2,0,2,2,2,1,4,0,2,4,4,1,0,0,0,8,0 1, 16, 4, 16, 9, 2, 4, 16, 9, 2, 0, 2, 2, 2, 1, 4, 0, 2, 4, 4, 1, 0, 0, 0, 8, 0
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
}; };
...@@ -168,5 +169,4 @@ char _codes[26] = { ...@@ -168,5 +169,4 @@ char _codes[26] = {
/* These prevent GH from becoming F */ /* These prevent GH from becoming F */
#define NOGHTOF(c) (ENCODE(c) & 16) /* BDH */ #define NOGHTOF(c) (ENCODE(c) & 16) /* BDH */
#endif /* FUZZYSTRMATCH_H */ #endif /* FUZZYSTRMATCH_H */
/* /*
* PostgreSQL type definitions for managed LargeObjects. * PostgreSQL type definitions for managed LargeObjects.
* *
* $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.8 2001/03/22 03:59:09 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.9 2001/10/25 05:49:19 momjian Exp $
* *
*/ */
...@@ -33,8 +33,8 @@ typedef Oid Blob; ...@@ -33,8 +33,8 @@ typedef Oid Blob;
*/ */
Blob *lo_in(char *str); /* Create from String */ Blob *lo_in(char *str); /* Create from String */
char *lo_out(Blob * addr);/* Output oid as String */ char *lo_out(Blob * addr); /* Output oid as String */
Oid lo_oid(Blob * addr);/* Return oid as an oid */ Oid lo_oid(Blob * addr); /* Return oid as an oid */
Blob *lo(Oid oid); /* Return Blob based on oid */ Blob *lo(Oid oid); /* Return Blob based on oid */
Datum lo_manage(PG_FUNCTION_ARGS); /* Trigger handler */ Datum lo_manage(PG_FUNCTION_ARGS); /* Trigger handler */
...@@ -64,7 +64,6 @@ lo_in(char *str) ...@@ -64,7 +64,6 @@ lo_in(char *str)
} }
else else
{ {
/* /*
* There is no Oid passed, so create a new one * There is no Oid passed, so create a new one
*/ */
...@@ -140,7 +139,7 @@ lo_manage(PG_FUNCTION_ARGS) ...@@ -140,7 +139,7 @@ lo_manage(PG_FUNCTION_ARGS)
TupleDesc tupdesc; /* Tuple Descriptor */ TupleDesc tupdesc; /* Tuple Descriptor */
HeapTuple rettuple; /* Tuple to be returned */ HeapTuple rettuple; /* Tuple to be returned */
bool isdelete; /* are we deleting? */ bool isdelete; /* are we deleting? */
HeapTuple newtuple = NULL;/* The new value for tuple */ HeapTuple newtuple = NULL; /* The new value for tuple */
HeapTuple trigtuple; /* The original value of tuple */ HeapTuple trigtuple; /* The original value of tuple */
if (!CALLED_AS_TRIGGER(fcinfo)) if (!CALLED_AS_TRIGGER(fcinfo))
......
...@@ -6,5 +6,4 @@ int unlisten(char *relname); ...@@ -6,5 +6,4 @@ int unlisten(char *relname);
int max(int x, int y); int max(int x, int y);
int min(int x, int y); int min(int x, int y);
int active_listeners(text *relname); int active_listeners(text *relname);
#endif #endif
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001; * copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* licence: BSD * licence: BSD
* *
* $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.4 2001/09/06 10:49:29 petere Exp $ * $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.5 2001/10/25 05:49:19 momjian Exp $
*/ */
#include "postgres.h" #include "postgres.h"
......
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.7 2001/03/22 06:16:06 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.8 2001/10/25 05:49:19 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
...@@ -38,8 +38,8 @@ load_lolist(LODumpMaster * pgLO) ...@@ -38,8 +38,8 @@ load_lolist(LODumpMaster * pgLO)
* NOTE: System tables including pg_largeobject will be ignored. * NOTE: System tables including pg_largeobject will be ignored.
* Otherwise we'd end up dumping all LOs, referenced or not. * Otherwise we'd end up dumping all LOs, referenced or not.
* *
* NOTE: the system oid column is ignored, as it has attnum < 1. * NOTE: the system oid column is ignored, as it has attnum < 1. This
* This shouldn't matter for correctness, but it saves time. * shouldn't matter for correctness, but it saves time.
*/ */
pgLO->res = PQexec(pgLO->conn, pgLO->res = PQexec(pgLO->conn,
"SELECT c.relname, a.attname " "SELECT c.relname, a.attname "
...@@ -107,7 +107,6 @@ pglo_export(LODumpMaster * pgLO) ...@@ -107,7 +107,6 @@ pglo_export(LODumpMaster * pgLO)
for (ll = pgLO->lolist; ll->lo_table != NULL; ll++) for (ll = pgLO->lolist; ll->lo_table != NULL; ll++)
{ {
/* /*
* Query: find the LOs referenced by this column * Query: find the LOs referenced by this column
*/ */
......
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.5 2001/03/22 06:16:06 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.6 2001/10/25 05:49:19 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
......
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.8 2001/03/22 06:16:06 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.9 2001/10/25 05:49:19 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
...@@ -304,7 +304,6 @@ usage() ...@@ -304,7 +304,6 @@ usage()
"-q run quietly\n" "-q run quietly\n"
"-w not dump, but show all LO in DB\n" "-w not dump, but show all LO in DB\n"
); /* puts() */ ); /* puts() */
#endif #endif
puts( puts(
......
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.4 2001/03/22 03:59:10 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.5 2001/10/25 05:49:19 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
...@@ -78,5 +78,4 @@ extern void index_file(LODumpMaster * pgLO); ...@@ -78,5 +78,4 @@ extern void index_file(LODumpMaster * pgLO);
extern void load_lolist(LODumpMaster * pgLO); extern void load_lolist(LODumpMaster * pgLO);
extern void pglo_export(LODumpMaster * pgLO); extern void pglo_export(LODumpMaster * pgLO);
extern void pglo_import(LODumpMaster * pgLO); extern void pglo_import(LODumpMaster * pgLO);
#endif /* PG_DUMPLO_H */ #endif /* PG_DUMPLO_H */
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.7 2001/10/25 00:55:48 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.8 2001/10/25 05:49:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -147,7 +147,6 @@ ReadControlFile(void) ...@@ -147,7 +147,6 @@ ReadControlFile(void)
if ((fd = open(ControlFilePath, O_RDONLY)) < 0) if ((fd = open(ControlFilePath, O_RDONLY)) < 0)
{ {
/* /*
* If pg_control is not there at all, or we can't read it, the * If pg_control is not there at all, or we can't read it, the
* odds are we've been handed a bad DataDir path, so give up. User * odds are we've been handed a bad DataDir path, so give up. User
...@@ -412,7 +411,6 @@ CheckControlVersion0(char *buffer, int len) ...@@ -412,7 +411,6 @@ CheckControlVersion0(char *buffer, int len)
(char *) malloc(_INTL_MAXLOGRECSZ)); (char *) malloc(_INTL_MAXLOGRECSZ));
if (record == NULL) if (record == NULL)
{ {
/* /*
* We have to guess at the checkpoint contents. * We have to guess at the checkpoint contents.
*/ */
...@@ -493,7 +491,7 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer) ...@@ -493,7 +491,7 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
readFile = XLogFileOpen(readId, readSeg); readFile = XLogFileOpen(readId, readSeg);
if (readFile < 0) if (readFile < 0)
goto next_record_is_invalid; goto next_record_is_invalid;
readOff = (uint32) (-1);/* force read to occur below */ readOff = (uint32) (-1); /* force read to occur below */
} }
targetPageOff = ((RecPtr->xrecoff % XLogSegSize) / BLCKSZ) * BLCKSZ; targetPageOff = ((RecPtr->xrecoff % XLogSegSize) / BLCKSZ) * BLCKSZ;
...@@ -617,7 +615,6 @@ GuessControlValues(void) ...@@ -617,7 +615,6 @@ GuessControlValues(void)
{ {
#ifdef USE_LOCALE #ifdef USE_LOCALE
char *localeptr; char *localeptr;
#endif #endif
/* /*
......
/* /*
* $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.11 2001/10/24 08:07:22 ishii Exp $ * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.12 2001/10/25 05:49:19 momjian Exp $
* *
* pgbench: a simple TPC-B like benchmark program for PostgreSQL * pgbench: a simple TPC-B like benchmark program for PostgreSQL
* written by Tatsuo Ishii * written by Tatsuo Ishii
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
/* for getrlimit */ /* for getrlimit */
#include <sys/resource.h> #include <sys/resource.h>
#endif /* WIN32 */ #endif /* WIN32 */
/******************************************************************** /********************************************************************
...@@ -67,7 +66,8 @@ int tps = 1; ...@@ -67,7 +66,8 @@ int tps = 1;
int remains; /* number of remained clients */ int remains; /* number of remained clients */
int is_connect; /* establish connection for each transactoin */ int is_connect; /* establish connection for each
* transactoin */
char *pghost = ""; char *pghost = "";
char *pgport = NULL; char *pgport = NULL;
...@@ -107,7 +107,8 @@ getrand(int min, int max) ...@@ -107,7 +107,8 @@ getrand(int min, int max)
} }
/* set up a connection to the backend */ /* set up a connection to the backend */
static PGconn *doConnect() static PGconn *
doConnect()
{ {
PGconn *con; PGconn *con;
...@@ -117,7 +118,7 @@ static PGconn *doConnect() ...@@ -117,7 +118,7 @@ static PGconn *doConnect()
{ {
fprintf(stderr, "Connection to database '%s' failed.\n", dbName); fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
fprintf(stderr, "Memory allocatin problem?\n"); fprintf(stderr, "Memory allocatin problem?\n");
return(NULL); return (NULL);
} }
if (PQstatus(con) == CONNECTION_BAD) if (PQstatus(con) == CONNECTION_BAD)
...@@ -129,7 +130,7 @@ static PGconn *doConnect() ...@@ -129,7 +130,7 @@ static PGconn *doConnect()
else else
fprintf(stderr, "No explanation from the backend\n"); fprintf(stderr, "No explanation from the backend\n");
return(NULL); return (NULL);
} }
return (con); return (con);
} }
...@@ -532,8 +533,8 @@ init() ...@@ -532,8 +533,8 @@ init()
if (j % 10000 == 0) if (j % 10000 == 0)
{ {
/* /*
* every 10000 tuples, we commit the copy command. * every 10000 tuples, we commit the copy command. this should
* this should avoid generating too much WAL logs * avoid generating too much WAL logs
*/ */
fprintf(stderr, "%d tuples done.\n", j); fprintf(stderr, "%d tuples done.\n", j);
if (PQputline(con, "\\.\n")) if (PQputline(con, "\\.\n"))
...@@ -547,6 +548,7 @@ init() ...@@ -547,6 +548,7 @@ init()
fprintf(stderr, "PQendcopy failed\n"); fprintf(stderr, "PQendcopy failed\n");
exit(1); exit(1);
} }
/* /*
* do a checkpoint to purge the old WAL logs * do a checkpoint to purge the old WAL logs
*/ */
...@@ -634,7 +636,6 @@ main(int argc, char **argv) ...@@ -634,7 +636,6 @@ main(int argc, char **argv)
#ifndef __CYGWIN__ #ifndef __CYGWIN__
struct rlimit rlim; struct rlimit rlim;
#endif #endif
PGconn *con; PGconn *con;
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n]) #define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
void void
Blowfish_encipher(blf_ctx *c, uint32 *x) Blowfish_encipher(blf_ctx * c, uint32 *x)
{ {
uint32 Xl; uint32 Xl;
uint32 Xr; uint32 Xr;
...@@ -71,21 +71,29 @@ Blowfish_encipher(blf_ctx *c, uint32 *x) ...@@ -71,21 +71,29 @@ Blowfish_encipher(blf_ctx *c, uint32 *x)
Xr = x[1]; Xr = x[1];
Xl ^= p[0]; Xl ^= p[0];
BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2); BLFRND(s, p, Xr, Xl, 1);
BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4); BLFRND(s, p, Xl, Xr, 2);
BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6); BLFRND(s, p, Xr, Xl, 3);
BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8); BLFRND(s, p, Xl, Xr, 4);
BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10); BLFRND(s, p, Xr, Xl, 5);
BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12); BLFRND(s, p, Xl, Xr, 6);
BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14); BLFRND(s, p, Xr, Xl, 7);
BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16); BLFRND(s, p, Xl, Xr, 8);
BLFRND(s, p, Xr, Xl, 9);
BLFRND(s, p, Xl, Xr, 10);
BLFRND(s, p, Xr, Xl, 11);
BLFRND(s, p, Xl, Xr, 12);
BLFRND(s, p, Xr, Xl, 13);
BLFRND(s, p, Xl, Xr, 14);
BLFRND(s, p, Xr, Xl, 15);
BLFRND(s, p, Xl, Xr, 16);
x[0] = Xr ^ p[17]; x[0] = Xr ^ p[17];
x[1] = Xl; x[1] = Xl;
} }
void void
Blowfish_decipher(blf_ctx *c, uint32 *x) Blowfish_decipher(blf_ctx * c, uint32 *x)
{ {
uint32 Xl; uint32 Xl;
uint32 Xr; uint32 Xr;
...@@ -96,28 +104,36 @@ Blowfish_decipher(blf_ctx *c, uint32 *x) ...@@ -96,28 +104,36 @@ Blowfish_decipher(blf_ctx *c, uint32 *x)
Xr = x[1]; Xr = x[1];
Xl ^= p[17]; Xl ^= p[17];
BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15); BLFRND(s, p, Xr, Xl, 16);
BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13); BLFRND(s, p, Xl, Xr, 15);
BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11); BLFRND(s, p, Xr, Xl, 14);
BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9); BLFRND(s, p, Xl, Xr, 13);
BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7); BLFRND(s, p, Xr, Xl, 12);
BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5); BLFRND(s, p, Xl, Xr, 11);
BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3); BLFRND(s, p, Xr, Xl, 10);
BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1); BLFRND(s, p, Xl, Xr, 9);
BLFRND(s, p, Xr, Xl, 8);
BLFRND(s, p, Xl, Xr, 7);
BLFRND(s, p, Xr, Xl, 6);
BLFRND(s, p, Xl, Xr, 5);
BLFRND(s, p, Xr, Xl, 4);
BLFRND(s, p, Xl, Xr, 3);
BLFRND(s, p, Xr, Xl, 2);
BLFRND(s, p, Xl, Xr, 1);
x[0] = Xr ^ p[0]; x[0] = Xr ^ p[0];
x[1] = Xl; x[1] = Xl;
} }
void void
Blowfish_initstate(blf_ctx *c) Blowfish_initstate(blf_ctx * c)
{ {
/* P-box and S-box tables initialized with digits of Pi */ /* P-box and S-box tables initialized with digits of Pi */
const blf_ctx initstate = const blf_ctx initstate =
{ { {{
{ {
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
...@@ -385,7 +401,7 @@ Blowfish_initstate(blf_ctx *c) ...@@ -385,7 +401,7 @@ Blowfish_initstate(blf_ctx *c)
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
0x9216d5d9, 0x8979fb1b 0x9216d5d9, 0x8979fb1b
} }; }};
*c = initstate; *c = initstate;
...@@ -401,7 +417,8 @@ Blowfish_stream2word(const uint8 *data, uint16 databytes, uint16 *current) ...@@ -401,7 +417,8 @@ Blowfish_stream2word(const uint8 *data, uint16 databytes, uint16 *current)
temp = 0x00000000; temp = 0x00000000;
j = *current; j = *current;
for (i = 0; i < 4; i++, j++) { for (i = 0; i < 4; i++, j++)
{
if (j >= databytes) if (j >= databytes)
j = 0; j = 0;
temp = (temp << 8) | data[j]; temp = (temp << 8) | data[j];
...@@ -412,7 +429,7 @@ Blowfish_stream2word(const uint8 *data, uint16 databytes, uint16 *current) ...@@ -412,7 +429,7 @@ Blowfish_stream2word(const uint8 *data, uint16 databytes, uint16 *current)
} }
void void
Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes) Blowfish_expand0state(blf_ctx * c, const uint8 *key, uint16 keybytes)
{ {
uint16 i; uint16 i;
uint16 j; uint16 j;
...@@ -421,7 +438,8 @@ Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes) ...@@ -421,7 +438,8 @@ Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes)
uint32 data[2]; uint32 data[2];
j = 0; j = 0;
for (i = 0; i < BLF_N + 2; i++) { for (i = 0; i < BLF_N + 2; i++)
{
/* Extract 4 int8 to 1 int32 from keystream */ /* Extract 4 int8 to 1 int32 from keystream */
temp = Blowfish_stream2word(key, keybytes, &j); temp = Blowfish_stream2word(key, keybytes, &j);
c->P[i] = c->P[i] ^ temp; c->P[i] = c->P[i] ^ temp;
...@@ -430,15 +448,18 @@ Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes) ...@@ -430,15 +448,18 @@ Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes)
j = 0; j = 0;
data[0] = 0x00000000; data[0] = 0x00000000;
data[1] = 0x00000000; data[1] = 0x00000000;
for (i = 0; i < BLF_N + 2; i += 2) { for (i = 0; i < BLF_N + 2; i += 2)
{
Blowfish_encipher(c, data); Blowfish_encipher(c, data);
c->P[i] = data[0]; c->P[i] = data[0];
c->P[i + 1] = data[1]; c->P[i + 1] = data[1];
} }
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++)
for (k = 0; k < 256; k += 2) { {
for (k = 0; k < 256; k += 2)
{
Blowfish_encipher(c, data); Blowfish_encipher(c, data);
c->S[i][k] = data[0]; c->S[i][k] = data[0];
...@@ -449,7 +470,7 @@ Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes) ...@@ -449,7 +470,7 @@ Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes)
void void
Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes, Blowfish_expandstate(blf_ctx * c, const uint8 *data, uint16 databytes,
const uint8 *key, uint16 keybytes) const uint8 *key, uint16 keybytes)
{ {
uint16 i; uint16 i;
...@@ -459,7 +480,8 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes, ...@@ -459,7 +480,8 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes,
uint32 d[2]; uint32 d[2];
j = 0; j = 0;
for (i = 0; i < BLF_N + 2; i++) { for (i = 0; i < BLF_N + 2; i++)
{
/* Extract 4 int8 to 1 int32 from keystream */ /* Extract 4 int8 to 1 int32 from keystream */
temp = Blowfish_stream2word(key, keybytes, &j); temp = Blowfish_stream2word(key, keybytes, &j);
c->P[i] = c->P[i] ^ temp; c->P[i] = c->P[i] ^ temp;
...@@ -468,7 +490,8 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes, ...@@ -468,7 +490,8 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes,
j = 0; j = 0;
d[0] = 0x00000000; d[0] = 0x00000000;
d[1] = 0x00000000; d[1] = 0x00000000;
for (i = 0; i < BLF_N + 2; i += 2) { for (i = 0; i < BLF_N + 2; i += 2)
{
d[0] ^= Blowfish_stream2word(data, databytes, &j); d[0] ^= Blowfish_stream2word(data, databytes, &j);
d[1] ^= Blowfish_stream2word(data, databytes, &j); d[1] ^= Blowfish_stream2word(data, databytes, &j);
Blowfish_encipher(c, d); Blowfish_encipher(c, d);
...@@ -477,9 +500,11 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes, ...@@ -477,9 +500,11 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes,
c->P[i + 1] = d[1]; c->P[i + 1] = d[1];
} }
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++)
for (k = 0; k < 256; k += 2) { {
d[0]^= Blowfish_stream2word(data, databytes, &j); for (k = 0; k < 256; k += 2)
{
d[0] ^= Blowfish_stream2word(data, databytes, &j);
d[1] ^= Blowfish_stream2word(data, databytes, &j); d[1] ^= Blowfish_stream2word(data, databytes, &j);
Blowfish_encipher(c, d); Blowfish_encipher(c, d);
...@@ -491,7 +516,7 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes, ...@@ -491,7 +516,7 @@ Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes,
} }
void void
blf_key(blf_ctx *c, const uint8 *k, uint16 len) blf_key(blf_ctx * c, const uint8 *k, uint16 len)
{ {
/* Initalize S-boxes and subkeys with Pi */ /* Initalize S-boxes and subkeys with Pi */
Blowfish_initstate(c); Blowfish_initstate(c);
...@@ -501,38 +526,43 @@ blf_key(blf_ctx *c, const uint8 *k, uint16 len) ...@@ -501,38 +526,43 @@ blf_key(blf_ctx *c, const uint8 *k, uint16 len)
} }
void void
blf_enc(blf_ctx *c, uint32 *data, uint16 blocks) blf_enc(blf_ctx * c, uint32 *data, uint16 blocks)
{ {
uint32 *d; uint32 *d;
uint16 i; uint16 i;
d = data; d = data;
for (i = 0; i < blocks; i++) { for (i = 0; i < blocks; i++)
{
Blowfish_encipher(c, d); Blowfish_encipher(c, d);
d += 2; d += 2;
} }
} }
void void
blf_dec(blf_ctx *c, uint32 *data, uint16 blocks) blf_dec(blf_ctx * c, uint32 *data, uint16 blocks)
{ {
uint32 *d; uint32 *d;
uint16 i; uint16 i;
d = data; d = data;
for (i = 0; i < blocks; i++) { for (i = 0; i < blocks; i++)
{
Blowfish_decipher(c, d); Blowfish_decipher(c, d);
d += 2; d += 2;
} }
} }
void void
blf_ecb_encrypt(blf_ctx *c, uint8 *data, uint32 len) blf_ecb_encrypt(blf_ctx * c, uint8 *data, uint32 len)
{ {
uint32 l, r, d[2]; uint32 l,
r,
d[2];
uint32 i; uint32 i;
for (i = 0; i < len; i += 8) { for (i = 0; i < len; i += 8)
{
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
d[0] = l; d[0] = l;
...@@ -553,12 +583,15 @@ blf_ecb_encrypt(blf_ctx *c, uint8 *data, uint32 len) ...@@ -553,12 +583,15 @@ blf_ecb_encrypt(blf_ctx *c, uint8 *data, uint32 len)
} }
void void
blf_ecb_decrypt(blf_ctx *c, uint8 *data, uint32 len) blf_ecb_decrypt(blf_ctx * c, uint8 *data, uint32 len)
{ {
uint32 l, r, d[2]; uint32 l,
r,
d[2];
uint32 i; uint32 i;
for (i = 0; i < len; i += 8) { for (i = 0; i < len; i += 8)
{
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
d[0] = l; d[0] = l;
...@@ -579,12 +612,16 @@ blf_ecb_decrypt(blf_ctx *c, uint8 *data, uint32 len) ...@@ -579,12 +612,16 @@ blf_ecb_decrypt(blf_ctx *c, uint8 *data, uint32 len)
} }
void void
blf_cbc_encrypt(blf_ctx *c, uint8 *iv, uint8 *data, uint32 len) blf_cbc_encrypt(blf_ctx * c, uint8 *iv, uint8 *data, uint32 len)
{ {
uint32 l, r, d[2]; uint32 l,
uint32 i, j; r,
d[2];
uint32 i,
j;
for (i = 0; i < len; i += 8) { for (i = 0; i < len; i += 8)
{
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
data[j] ^= iv[j]; data[j] ^= iv[j];
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
...@@ -608,15 +645,19 @@ blf_cbc_encrypt(blf_ctx *c, uint8 *iv, uint8 *data, uint32 len) ...@@ -608,15 +645,19 @@ blf_cbc_encrypt(blf_ctx *c, uint8 *iv, uint8 *data, uint32 len)
} }
void void
blf_cbc_decrypt(blf_ctx *c, uint8 *iva, uint8 *data, uint32 len) blf_cbc_decrypt(blf_ctx * c, uint8 *iva, uint8 *data, uint32 len)
{ {
uint32 l, r, d[2]; uint32 l,
r,
d[2];
uint8 *iv; uint8 *iv;
uint32 i, j; uint32 i,
j;
iv = data + len - 16; iv = data + len - 16;
data = data + len - 8; data = data + len - 8;
for (i = len - 8; i >= 8; i -= 8) { for (i = len - 8; i >= 8; i -= 8)
{
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
d[0] = l; d[0] = l;
......
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */ #define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
/* Blowfish context */ /* Blowfish context */
typedef struct BlowfishContext { typedef struct BlowfishContext
{
uint32 S[4][256]; /* S-Boxes */ uint32 S[4][256]; /* S-Boxes */
uint32 P[BLF_N + 2]; /* Subkeys */ uint32 P[BLF_N + 2]; /* Subkeys */
} blf_ctx; } blf_ctx;
...@@ -57,26 +58,25 @@ typedef struct BlowfishContext { ...@@ -57,26 +58,25 @@ typedef struct BlowfishContext {
* Blowfish_expand0state( state, key, keylen ) * Blowfish_expand0state( state, key, keylen )
*/ */
void Blowfish_encipher (blf_ctx *, uint32 *); void Blowfish_encipher(blf_ctx *, uint32 *);
void Blowfish_decipher (blf_ctx *, uint32 *); void Blowfish_decipher(blf_ctx *, uint32 *);
void Blowfish_initstate (blf_ctx *); void Blowfish_initstate(blf_ctx *);
void Blowfish_expand0state (blf_ctx *, const uint8 *, uint16); void Blowfish_expand0state(blf_ctx *, const uint8 *, uint16);
void Blowfish_expandstate void Blowfish_expandstate
(blf_ctx *, const uint8 *, uint16, const uint8 *, uint16); (blf_ctx *, const uint8 *, uint16, const uint8 *, uint16);
/* Standard Blowfish */ /* Standard Blowfish */
void blf_key (blf_ctx *, const uint8 *, uint16); void blf_key(blf_ctx *, const uint8 *, uint16);
void blf_enc (blf_ctx *, uint32 *, uint16); void blf_enc(blf_ctx *, uint32 *, uint16);
void blf_dec (blf_ctx *, uint32 *, uint16); void blf_dec(blf_ctx *, uint32 *, uint16);
/* Converts uint8 to uint32 */ /* Converts uint8 to uint32 */
uint32 Blowfish_stream2word (const uint8 *, uint16, uint16 *); uint32 Blowfish_stream2word(const uint8 *, uint16, uint16 *);
void blf_ecb_encrypt (blf_ctx *, uint8 *, uint32); void blf_ecb_encrypt(blf_ctx *, uint8 *, uint32);
void blf_ecb_decrypt (blf_ctx *, uint8 *, uint32); void blf_ecb_decrypt(blf_ctx *, uint8 *, uint32);
void blf_cbc_encrypt (blf_ctx *, uint8 *, uint8 *, uint32);
void blf_cbc_decrypt (blf_ctx *, uint8 *, uint8 *, uint32);
void blf_cbc_encrypt(blf_ctx *, uint8 *, uint8 *, uint32);
void blf_cbc_decrypt(blf_ctx *, uint8 *, uint8 *, uint32);
#endif #endif
...@@ -57,7 +57,8 @@ typedef unsigned int BF_word; ...@@ -57,7 +57,8 @@ typedef unsigned int BF_word;
typedef BF_word BF_key[BF_N + 2]; typedef BF_word BF_key[BF_N + 2];
typedef struct { typedef struct
{
BF_word S[4][0x100]; BF_word S[4][0x100];
BF_key P; BF_key P;
} BF_ctx; } BF_ctx;
...@@ -347,7 +348,7 @@ static BF_ctx BF_init_state = { ...@@ -347,7 +348,7 @@ static BF_ctx BF_init_state = {
}; };
static unsigned char BF_itoa64[64 + 1] = static unsigned char BF_itoa64[64 + 1] =
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
static unsigned char BF_atoi64[0x60] = { static unsigned char BF_atoi64[0x60] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1,
...@@ -367,22 +368,30 @@ do { \ ...@@ -367,22 +368,30 @@ do { \
(dst) = tmp; \ (dst) = tmp; \
} while (0) } while (0)
static int BF_decode(BF_word *dst, const char *src, int size) static int
BF_decode(BF_word * dst, const char *src, int size)
{ {
unsigned char *dptr = (unsigned char *)dst; unsigned char *dptr = (unsigned char *) dst;
unsigned char *end = dptr + size; unsigned char *end = dptr + size;
unsigned char *sptr = (unsigned char *)src; unsigned char *sptr = (unsigned char *) src;
unsigned int tmp, c1, c2, c3, c4; unsigned int tmp,
c1,
do { c2,
c3,
c4;
do
{
BF_safe_atoi64(c1, *sptr++); BF_safe_atoi64(c1, *sptr++);
BF_safe_atoi64(c2, *sptr++); BF_safe_atoi64(c2, *sptr++);
*dptr++ = (c1 << 2) | ((c2 & 0x30) >> 4); *dptr++ = (c1 << 2) | ((c2 & 0x30) >> 4);
if (dptr >= end) break; if (dptr >= end)
break;
BF_safe_atoi64(c3, *sptr++); BF_safe_atoi64(c3, *sptr++);
*dptr++ = ((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2); *dptr++ = ((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2);
if (dptr >= end) break; if (dptr >= end)
break;
BF_safe_atoi64(c4, *sptr++); BF_safe_atoi64(c4, *sptr++);
*dptr++ = ((c3 & 0x03) << 6) | c4; *dptr++ = ((c3 & 0x03) << 6) | c4;
...@@ -391,18 +400,22 @@ static int BF_decode(BF_word *dst, const char *src, int size) ...@@ -391,18 +400,22 @@ static int BF_decode(BF_word *dst, const char *src, int size)
return 0; return 0;
} }
static void BF_encode(char *dst, const BF_word *src, int size) static void
BF_encode(char *dst, const BF_word * src, int size)
{ {
unsigned char *sptr = (unsigned char *)src; unsigned char *sptr = (unsigned char *) src;
unsigned char *end = sptr + size; unsigned char *end = sptr + size;
unsigned char *dptr = (unsigned char *)dst; unsigned char *dptr = (unsigned char *) dst;
unsigned int c1, c2; unsigned int c1,
c2;
do { do
{
c1 = *sptr++; c1 = *sptr++;
*dptr++ = BF_itoa64[c1 >> 2]; *dptr++ = BF_itoa64[c1 >> 2];
c1 = (c1 & 0x03) << 4; c1 = (c1 & 0x03) << 4;
if (sptr >= end) { if (sptr >= end)
{
*dptr++ = BF_itoa64[c1]; *dptr++ = BF_itoa64[c1];
break; break;
} }
...@@ -411,7 +424,8 @@ static void BF_encode(char *dst, const BF_word *src, int size) ...@@ -411,7 +424,8 @@ static void BF_encode(char *dst, const BF_word *src, int size)
c1 |= c2 >> 4; c1 |= c2 >> 4;
*dptr++ = BF_itoa64[c1]; *dptr++ = BF_itoa64[c1];
c1 = (c2 & 0x0f) << 2; c1 = (c2 & 0x0f) << 2;
if (sptr >= end) { if (sptr >= end)
{
*dptr++ = BF_itoa64[c1]; *dptr++ = BF_itoa64[c1];
break; break;
} }
...@@ -423,14 +437,16 @@ static void BF_encode(char *dst, const BF_word *src, int size) ...@@ -423,14 +437,16 @@ static void BF_encode(char *dst, const BF_word *src, int size)
} while (sptr < end); } while (sptr < end);
} }
static void BF_swap(BF_word *x, int count) static void
BF_swap(BF_word * x, int count)
{ {
static int endianness_check = 1; static int endianness_check = 1;
char *is_little_endian = (char *)&endianness_check; char *is_little_endian = (char *) &endianness_check;
BF_word tmp; BF_word tmp;
if (*is_little_endian) if (*is_little_endian)
do { do
{
tmp = *x; tmp = *x;
tmp = (tmp << 16) | (tmp >> 16); tmp = (tmp << 16) | (tmp >> 16);
*x++ = ((tmp & 0x00FF00FF) << 8) | ((tmp >> 8) & 0x00FF00FF); *x++ = ((tmp & 0x00FF00FF) << 8) | ((tmp >> 8) & 0x00FF00FF);
...@@ -504,7 +520,8 @@ static void BF_swap(BF_word *x, int count) ...@@ -504,7 +520,8 @@ static void BF_swap(BF_word *x, int count)
#if BF_ASM #if BF_ASM
extern void _BF_body_r(BF_ctx *ctx); extern void _BF_body_r(BF_ctx * ctx);
#define BF_body() \ #define BF_body() \
_BF_body_r(&data.ctx); _BF_body_r(&data.ctx);
...@@ -527,22 +544,28 @@ extern void _BF_body_r(BF_ctx *ctx); ...@@ -527,22 +544,28 @@ extern void _BF_body_r(BF_ctx *ctx);
*(ptr - 2) = L; \ *(ptr - 2) = L; \
*(ptr - 1) = R; \ *(ptr - 1) = R; \
} while (ptr < &data.ctx.S[3][0xFF]); } while (ptr < &data.ctx.S[3][0xFF]);
#endif #endif
static void BF_set_key(const char *key, BF_key expanded, BF_key initial) static void
BF_set_key(const char *key, BF_key expanded, BF_key initial)
{ {
const char *ptr = key; const char *ptr = key;
int i, j; int i,
j;
BF_word tmp; BF_word tmp;
for (i = 0; i < BF_N + 2; i++) { for (i = 0; i < BF_N + 2; i++)
{
tmp = 0; tmp = 0;
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++)
{
tmp <<= 8; tmp <<= 8;
tmp |= *ptr; tmp |= *ptr;
if (!*ptr) ptr = key; else ptr++; if (!*ptr)
ptr = key;
else
ptr++;
} }
expanded[i] = tmp; expanded[i] = tmp;
...@@ -550,24 +573,32 @@ static void BF_set_key(const char *key, BF_key expanded, BF_key initial) ...@@ -550,24 +573,32 @@ static void BF_set_key(const char *key, BF_key expanded, BF_key initial)
} }
} }
char *_crypt_blowfish_rn(const char *key, const char *setting, char *
_crypt_blowfish_rn(const char *key, const char *setting,
char *output, int size) char *output, int size)
{ {
struct { struct
{
BF_ctx ctx; BF_ctx ctx;
BF_key expanded_key; BF_key expanded_key;
union { union
{
BF_word salt[4]; BF_word salt[4];
BF_word output[6]; BF_word output[6];
} binary; } binary;
} data; } data;
BF_word L, R; BF_word L,
BF_word tmp1, tmp2, tmp3, tmp4; R;
BF_word tmp1,
tmp2,
tmp3,
tmp4;
BF_word *ptr; BF_word *ptr;
BF_word count; BF_word count;
int i; int i;
if (size < 7 + 22 + 31 + 1) { if (size < 7 + 22 + 31 + 1)
{
__set_errno(ERANGE); __set_errno(ERANGE);
return NULL; return NULL;
} }
...@@ -578,13 +609,15 @@ char *_crypt_blowfish_rn(const char *key, const char *setting, ...@@ -578,13 +609,15 @@ char *_crypt_blowfish_rn(const char *key, const char *setting,
setting[3] != '$' || setting[3] != '$' ||
setting[4] < '0' || setting[4] > '3' || setting[4] < '0' || setting[4] > '3' ||
setting[5] < '0' || setting[5] > '9' || setting[5] < '0' || setting[5] > '9' ||
setting[6] != '$') { setting[6] != '$')
{
__set_errno(EINVAL); __set_errno(EINVAL);
return NULL; return NULL;
} }
count = (BF_word)1 << ((setting[4] - '0') * 10 + (setting[5] - '0')); count = (BF_word) 1 << ((setting[4] - '0') * 10 + (setting[5] - '0'));
if (count < 16 || BF_decode(data.binary.salt, &setting[7], 16)) { if (count < 16 || BF_decode(data.binary.salt, &setting[7], 16))
{
memset(data.binary.salt, 0, sizeof(data.binary.salt)); memset(data.binary.salt, 0, sizeof(data.binary.salt));
__set_errno(EINVAL); __set_errno(EINVAL);
return NULL; return NULL;
...@@ -596,7 +629,8 @@ char *_crypt_blowfish_rn(const char *key, const char *setting, ...@@ -596,7 +629,8 @@ char *_crypt_blowfish_rn(const char *key, const char *setting,
memcpy(data.ctx.S, BF_init_state.S, sizeof(data.ctx.S)); memcpy(data.ctx.S, BF_init_state.S, sizeof(data.ctx.S));
L = R = 0; L = R = 0;
for (i = 0; i < BF_N + 2; i += 2) { for (i = 0; i < BF_N + 2; i += 2)
{
L ^= data.binary.salt[i & 2]; L ^= data.binary.salt[i & 2];
R ^= data.binary.salt[(i & 2) + 1]; R ^= data.binary.salt[(i & 2) + 1];
BF_ENCRYPT; BF_ENCRYPT;
...@@ -605,7 +639,8 @@ char *_crypt_blowfish_rn(const char *key, const char *setting, ...@@ -605,7 +639,8 @@ char *_crypt_blowfish_rn(const char *key, const char *setting,
} }
ptr = data.ctx.S[0]; ptr = data.ctx.S[0];
do { do
{
ptr += 4; ptr += 4;
L ^= data.binary.salt[(BF_N + 2) & 3]; L ^= data.binary.salt[(BF_N + 2) & 3];
R ^= data.binary.salt[(BF_N + 3) & 3]; R ^= data.binary.salt[(BF_N + 3) & 3];
...@@ -620,7 +655,8 @@ char *_crypt_blowfish_rn(const char *key, const char *setting, ...@@ -620,7 +655,8 @@ char *_crypt_blowfish_rn(const char *key, const char *setting,
*(ptr - 1) = R; *(ptr - 1) = R;
} while (ptr < &data.ctx.S[3][0xFF]); } while (ptr < &data.ctx.S[3][0xFF]);
do { do
{
data.ctx.P[0] ^= data.expanded_key[0]; data.ctx.P[0] ^= data.expanded_key[0];
data.ctx.P[1] ^= data.expanded_key[1]; data.ctx.P[1] ^= data.expanded_key[1];
data.ctx.P[2] ^= data.expanded_key[2]; data.ctx.P[2] ^= data.expanded_key[2];
...@@ -668,12 +704,14 @@ char *_crypt_blowfish_rn(const char *key, const char *setting, ...@@ -668,12 +704,14 @@ char *_crypt_blowfish_rn(const char *key, const char *setting,
BF_body(); BF_body();
} while (--count); } while (--count);
for (i = 0; i < 6; i += 2) { for (i = 0; i < 6; i += 2)
{
L = BF_magic_w[i]; L = BF_magic_w[i];
R = BF_magic_w[i + 1]; R = BF_magic_w[i + 1];
count = 64; count = 64;
do { do
{
BF_ENCRYPT; BF_ENCRYPT;
} while (--count); } while (--count);
...@@ -683,7 +721,7 @@ char *_crypt_blowfish_rn(const char *key, const char *setting, ...@@ -683,7 +721,7 @@ char *_crypt_blowfish_rn(const char *key, const char *setting,
memcpy(output, setting, 7 + 22 - 1); memcpy(output, setting, 7 + 22 - 1);
output[7 + 22 - 1] = BF_itoa64[(int) output[7 + 22 - 1] = BF_itoa64[(int)
BF_atoi64[(int)setting[7 + 22 - 1] - 0x20] & 0x30]; BF_atoi64[(int) setting[7 + 22 - 1] - 0x20] & 0x30];
/* This has to be bug-compatible with the original implementation, so /* This has to be bug-compatible with the original implementation, so
* only encode 23 of the 24 bytes. :-) */ * only encode 23 of the 24 bytes. :-) */
...@@ -698,4 +736,3 @@ char *_crypt_blowfish_rn(const char *key, const char *setting, ...@@ -698,4 +736,3 @@ char *_crypt_blowfish_rn(const char *key, const char *setting,
return output; return output;
} }
...@@ -244,8 +244,8 @@ des_init() ...@@ -244,8 +244,8 @@ des_init()
} }
/* /*
* Convert the inverted S-boxes into 4 arrays of 8 bits. * Convert the inverted S-boxes into 4 arrays of 8 bits. Each will
* Each will handle 12 bits of the S-box input. * handle 12 bits of the S-box input.
*/ */
for (b = 0; b < 4; b++) for (b = 0; b < 4; b++)
for (i = 0; i < 64; i++) for (i = 0; i < 64; i++)
...@@ -409,10 +409,9 @@ des_setkey(const char *key) ...@@ -409,10 +409,9 @@ des_setkey(const char *key)
&& rawkey1 == old_rawkey1) && rawkey1 == old_rawkey1)
{ {
/* /*
* Already setup for this key. * Already setup for this key. This optimisation fails on a zero
* This optimisation fails on a zero key (which is weak and * key (which is weak and has bad parity anyway) in order to
* has bad parity anyway) in order to simplify the starting * simplify the starting conditions.
* conditions.
*/ */
return (0); return (0);
} }
...@@ -438,6 +437,7 @@ des_setkey(const char *key) ...@@ -438,6 +437,7 @@ des_setkey(const char *key)
| key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
| key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
| key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
/* /*
* Rotate subkeys and do compression permutation. * Rotate subkeys and do compression permutation.
*/ */
...@@ -476,7 +476,7 @@ des_setkey(const char *key) ...@@ -476,7 +476,7 @@ des_setkey(const char *key)
} }
static int static int
do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count) do_des(uint32 l_in, uint32 r_in, uint32 *l_out, uint32 *r_out, int count)
{ {
/* /*
* l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
...@@ -556,21 +556,24 @@ do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count) ...@@ -556,21 +556,24 @@ do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count)
| ((r & 0x000001f8) << 3) | ((r & 0x000001f8) << 3)
| ((r & 0x0000001f) << 1) | ((r & 0x0000001f) << 1)
| ((r & 0x80000000) >> 31); | ((r & 0x80000000) >> 31);
/* /*
* Do salting for crypt() and friends, and * Do salting for crypt() and friends, and XOR with the
* XOR with the permuted key. * permuted key.
*/ */
f = (r48l ^ r48r) & saltbits; f = (r48l ^ r48r) & saltbits;
r48l ^= f ^ *kl++; r48l ^= f ^ *kl++;
r48r ^= f ^ *kr++; r48r ^= f ^ *kr++;
/* /*
* Do sbox lookups (which shrink it back to 32 bits) * Do sbox lookups (which shrink it back to 32 bits) and do
* and do the pbox permutation at the same time. * the pbox permutation at the same time.
*/ */
f = psbox[0][m_sbox[0][r48l >> 12]] f = psbox[0][m_sbox[0][r48l >> 12]]
| psbox[1][m_sbox[1][r48l & 0xfff]] | psbox[1][m_sbox[1][r48l & 0xfff]]
| psbox[2][m_sbox[2][r48r >> 12]] | psbox[2][m_sbox[2][r48r >> 12]]
| psbox[3][m_sbox[3][r48r & 0xfff]]; | psbox[3][m_sbox[3][r48r & 0xfff]];
/* /*
* Now that we've permuted things, complete f(). * Now that we've permuted things, complete f().
*/ */
...@@ -581,6 +584,7 @@ do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count) ...@@ -581,6 +584,7 @@ do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count)
r = l; r = l;
l = f; l = f;
} }
/* /*
* Do final permutation (inverse of IP). * Do final permutation (inverse of IP).
*/ */
...@@ -654,8 +658,8 @@ px_crypt_des(const char *key, const char *setting) ...@@ -654,8 +658,8 @@ px_crypt_des(const char *key, const char *setting)
/* /*
* Copy the key, shifting each character up by one bit * Copy the key, shifting each character up by one bit and padding
* and padding with zeros. * with zeros.
*/ */
q = (uint8 *) keybuf; q = (uint8 *) keybuf;
while (q - (uint8 *) keybuf - 8) while (q - (uint8 *) keybuf - 8)
...@@ -670,9 +674,8 @@ px_crypt_des(const char *key, const char *setting) ...@@ -670,9 +674,8 @@ px_crypt_des(const char *key, const char *setting)
if (*setting == _PASSWORD_EFMT1) if (*setting == _PASSWORD_EFMT1)
{ {
/* /*
* "new"-style: * "new"-style: setting - underscore, 4 bytes of count, 4 bytes of
* setting - underscore, 4 bytes of count, 4 bytes of salt * salt key - unlimited characters
* key - unlimited characters
*/ */
for (i = 1, count = 0L; i < 5; i++) for (i = 1, count = 0L; i < 5; i++)
count |= ascii_to_bin(setting[i]) << (i - 1) * 6; count |= ascii_to_bin(setting[i]) << (i - 1) * 6;
...@@ -687,6 +690,7 @@ px_crypt_des(const char *key, const char *setting) ...@@ -687,6 +690,7 @@ px_crypt_des(const char *key, const char *setting)
*/ */
if (des_cipher((uint8 *) keybuf, (uint8 *) keybuf, 0L, 1)) if (des_cipher((uint8 *) keybuf, (uint8 *) keybuf, 0L, 1))
return (NULL); return (NULL);
/* /*
* And XOR with the next 8 characters of the key. * And XOR with the next 8 characters of the key.
*/ */
...@@ -700,11 +704,10 @@ px_crypt_des(const char *key, const char *setting) ...@@ -700,11 +704,10 @@ px_crypt_des(const char *key, const char *setting)
strncpy(output, setting, 9); strncpy(output, setting, 9);
/* /*
* Double check that we weren't given a short setting. * Double check that we weren't given a short setting. If we were,
* If we were, the above code will probably have created * the above code will probably have created wierd values for
* wierd values for count and salt, but we don't really care. * count and salt, but we don't really care. Just make sure the
* Just make sure the output string doesn't have an extra * output string doesn't have an extra NUL in it.
* NUL in it.
*/ */
output[9] = '\0'; output[9] = '\0';
p = output + strlen(output); p = output + strlen(output);
...@@ -713,9 +716,7 @@ px_crypt_des(const char *key, const char *setting) ...@@ -713,9 +716,7 @@ px_crypt_des(const char *key, const char *setting)
#endif /* !DISABLE_XDES */ #endif /* !DISABLE_XDES */
{ {
/* /*
* "old"-style: * "old"-style: setting - 2 bytes of salt key - up to 8 characters
* setting - 2 bytes of salt
* key - up to 8 characters
*/ */
count = 25; count = 25;
...@@ -723,22 +724,24 @@ px_crypt_des(const char *key, const char *setting) ...@@ -723,22 +724,24 @@ px_crypt_des(const char *key, const char *setting)
| ascii_to_bin(setting[0]); | ascii_to_bin(setting[0]);
output[0] = setting[0]; output[0] = setting[0];
/* /*
* If the encrypted password that the salt was extracted from * If the encrypted password that the salt was extracted from is
* is only 1 character long, the salt will be corrupted. We * only 1 character long, the salt will be corrupted. We need to
* need to ensure that the output string doesn't have an extra * ensure that the output string doesn't have an extra NUL in it!
* NUL in it!
*/ */
output[1] = setting[1] ? setting[1] : output[0]; output[1] = setting[1] ? setting[1] : output[0];
p = output + 2; p = output + 2;
} }
setup_salt(salt); setup_salt(salt);
/* /*
* Do it. * Do it.
*/ */
if (do_des(0L, 0L, &r0, &r1, count)) if (do_des(0L, 0L, &r0, &r1, count))
return (NULL); return (NULL);
/* /*
* Now encode the result... * Now encode the result...
*/ */
......
...@@ -22,25 +22,29 @@ ...@@ -22,25 +22,29 @@
typedef unsigned int BF_word; typedef unsigned int BF_word;
unsigned char _crypt_itoa64[64 + 1] = unsigned char _crypt_itoa64[64 + 1] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char *_crypt_gensalt_traditional_rn(unsigned long count, char *
_crypt_gensalt_traditional_rn(unsigned long count,
const char *input, int size, char *output, int output_size) const char *input, int size, char *output, int output_size)
{ {
if (size < 2 || output_size < 2 + 1 || (count && count != 25)) { if (size < 2 || output_size < 2 + 1 || (count && count != 25))
if (output_size > 0) output[0] = '\0'; {
if (output_size > 0)
output[0] = '\0';
__set_errno((output_size < 2 + 1) ? ERANGE : EINVAL); __set_errno((output_size < 2 + 1) ? ERANGE : EINVAL);
return NULL; return NULL;
} }
output[0] = _crypt_itoa64[(unsigned int)input[0] & 0x3f]; output[0] = _crypt_itoa64[(unsigned int) input[0] & 0x3f];
output[1] = _crypt_itoa64[(unsigned int)input[1] & 0x3f]; output[1] = _crypt_itoa64[(unsigned int) input[1] & 0x3f];
output[2] = '\0'; output[2] = '\0';
return output; return output;
} }
char *_crypt_gensalt_extended_rn(unsigned long count, char *
_crypt_gensalt_extended_rn(unsigned long count,
const char *input, int size, char *output, int output_size) const char *input, int size, char *output, int output_size)
{ {
unsigned long value; unsigned long value;
...@@ -48,22 +52,25 @@ char *_crypt_gensalt_extended_rn(unsigned long count, ...@@ -48,22 +52,25 @@ char *_crypt_gensalt_extended_rn(unsigned long count,
/* Even iteration counts make it easier to detect weak DES keys from a look /* Even iteration counts make it easier to detect weak DES keys from a look
* at the hash, so they should be avoided */ * at the hash, so they should be avoided */
if (size < 3 || output_size < 1 + 4 + 4 + 1 || if (size < 3 || output_size < 1 + 4 + 4 + 1 ||
(count && (count > 0xffffff || !(count & 1)))) { (count && (count > 0xffffff || !(count & 1))))
if (output_size > 0) output[0] = '\0'; {
if (output_size > 0)
output[0] = '\0';
__set_errno((output_size < 1 + 4 + 4 + 1) ? ERANGE : EINVAL); __set_errno((output_size < 1 + 4 + 4 + 1) ? ERANGE : EINVAL);
return NULL; return NULL;
} }
if (!count) count = 725; if (!count)
count = 725;
output[0] = '_'; output[0] = '_';
output[1] = _crypt_itoa64[count & 0x3f]; output[1] = _crypt_itoa64[count & 0x3f];
output[2] = _crypt_itoa64[(count >> 6) & 0x3f]; output[2] = _crypt_itoa64[(count >> 6) & 0x3f];
output[3] = _crypt_itoa64[(count >> 12) & 0x3f]; output[3] = _crypt_itoa64[(count >> 12) & 0x3f];
output[4] = _crypt_itoa64[(count >> 18) & 0x3f]; output[4] = _crypt_itoa64[(count >> 18) & 0x3f];
value = (unsigned long)input[0] | value = (unsigned long) input[0] |
((unsigned long)input[1] << 8) | ((unsigned long) input[1] << 8) |
((unsigned long)input[2] << 16); ((unsigned long) input[2] << 16);
output[5] = _crypt_itoa64[value & 0x3f]; output[5] = _crypt_itoa64[value & 0x3f];
output[6] = _crypt_itoa64[(value >> 6) & 0x3f]; output[6] = _crypt_itoa64[(value >> 6) & 0x3f];
output[7] = _crypt_itoa64[(value >> 12) & 0x3f]; output[7] = _crypt_itoa64[(value >> 12) & 0x3f];
...@@ -73,13 +80,16 @@ char *_crypt_gensalt_extended_rn(unsigned long count, ...@@ -73,13 +80,16 @@ char *_crypt_gensalt_extended_rn(unsigned long count,
return output; return output;
} }
char *_crypt_gensalt_md5_rn(unsigned long count, char *
_crypt_gensalt_md5_rn(unsigned long count,
const char *input, int size, char *output, int output_size) const char *input, int size, char *output, int output_size)
{ {
unsigned long value; unsigned long value;
if (size < 3 || output_size < 3 + 4 + 1 || (count && count != 1000)) { if (size < 3 || output_size < 3 + 4 + 1 || (count && count != 1000))
if (output_size > 0) output[0] = '\0'; {
if (output_size > 0)
output[0] = '\0';
__set_errno((output_size < 3 + 4 + 1) ? ERANGE : EINVAL); __set_errno((output_size < 3 + 4 + 1) ? ERANGE : EINVAL);
return NULL; return NULL;
} }
...@@ -87,19 +97,20 @@ char *_crypt_gensalt_md5_rn(unsigned long count, ...@@ -87,19 +97,20 @@ char *_crypt_gensalt_md5_rn(unsigned long count,
output[0] = '$'; output[0] = '$';
output[1] = '1'; output[1] = '1';
output[2] = '$'; output[2] = '$';
value = (unsigned long)input[0] | value = (unsigned long) input[0] |
((unsigned long)input[1] << 8) | ((unsigned long) input[1] << 8) |
((unsigned long)input[2] << 16); ((unsigned long) input[2] << 16);
output[3] = _crypt_itoa64[value & 0x3f]; output[3] = _crypt_itoa64[value & 0x3f];
output[4] = _crypt_itoa64[(value >> 6) & 0x3f]; output[4] = _crypt_itoa64[(value >> 6) & 0x3f];
output[5] = _crypt_itoa64[(value >> 12) & 0x3f]; output[5] = _crypt_itoa64[(value >> 12) & 0x3f];
output[6] = _crypt_itoa64[(value >> 18) & 0x3f]; output[6] = _crypt_itoa64[(value >> 18) & 0x3f];
output[7] = '\0'; output[7] = '\0';
if (size >= 6 && output_size >= 3 + 4 + 4 + 1) { if (size >= 6 && output_size >= 3 + 4 + 4 + 1)
value = (unsigned long)input[3] | {
((unsigned long)input[4] << 8) | value = (unsigned long) input[3] |
((unsigned long)input[5] << 16); ((unsigned long) input[4] << 8) |
((unsigned long) input[5] << 16);
output[7] = _crypt_itoa64[value & 0x3f]; output[7] = _crypt_itoa64[value & 0x3f];
output[8] = _crypt_itoa64[(value >> 6) & 0x3f]; output[8] = _crypt_itoa64[(value >> 6) & 0x3f];
output[9] = _crypt_itoa64[(value >> 12) & 0x3f]; output[9] = _crypt_itoa64[(value >> 12) & 0x3f];
...@@ -113,20 +124,24 @@ char *_crypt_gensalt_md5_rn(unsigned long count, ...@@ -113,20 +124,24 @@ char *_crypt_gensalt_md5_rn(unsigned long count,
static unsigned char BF_itoa64[64 + 1] = static unsigned char BF_itoa64[64 + 1] =
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
static void BF_encode(char *dst, const BF_word *src, int size) static void
BF_encode(char *dst, const BF_word * src, int size)
{ {
unsigned char *sptr = (unsigned char *)src; unsigned char *sptr = (unsigned char *) src;
unsigned char *end = sptr + size; unsigned char *end = sptr + size;
unsigned char *dptr = (unsigned char *)dst; unsigned char *dptr = (unsigned char *) dst;
unsigned int c1, c2; unsigned int c1,
c2;
do { do
{
c1 = *sptr++; c1 = *sptr++;
*dptr++ = BF_itoa64[c1 >> 2]; *dptr++ = BF_itoa64[c1 >> 2];
c1 = (c1 & 0x03) << 4; c1 = (c1 & 0x03) << 4;
if (sptr >= end) { if (sptr >= end)
{
*dptr++ = BF_itoa64[c1]; *dptr++ = BF_itoa64[c1];
break; break;
} }
...@@ -135,7 +150,8 @@ static void BF_encode(char *dst, const BF_word *src, int size) ...@@ -135,7 +150,8 @@ static void BF_encode(char *dst, const BF_word *src, int size)
c1 |= c2 >> 4; c1 |= c2 >> 4;
*dptr++ = BF_itoa64[c1]; *dptr++ = BF_itoa64[c1];
c1 = (c2 & 0x0f) << 2; c1 = (c2 & 0x0f) << 2;
if (sptr >= end) { if (sptr >= end)
{
*dptr++ = BF_itoa64[c1]; *dptr++ = BF_itoa64[c1];
break; break;
} }
...@@ -147,17 +163,21 @@ static void BF_encode(char *dst, const BF_word *src, int size) ...@@ -147,17 +163,21 @@ static void BF_encode(char *dst, const BF_word *src, int size)
} while (sptr < end); } while (sptr < end);
} }
char *_crypt_gensalt_blowfish_rn(unsigned long count, char *
_crypt_gensalt_blowfish_rn(unsigned long count,
const char *input, int size, char *output, int output_size) const char *input, int size, char *output, int output_size)
{ {
if (size < 16 || output_size < 7 + 22 + 1 || if (size < 16 || output_size < 7 + 22 + 1 ||
(count && (count < 4 || count > 31))) { (count && (count < 4 || count > 31)))
if (output_size > 0) output[0] = '\0'; {
if (output_size > 0)
output[0] = '\0';
__set_errno((output_size < 7 + 22 + 1) ? ERANGE : EINVAL); __set_errno((output_size < 7 + 22 + 1) ? ERANGE : EINVAL);
return NULL; return NULL;
} }
if (!count) count = 5; if (!count)
count = 5;
output[0] = '$'; output[0] = '$';
output[1] = '2'; output[1] = '2';
...@@ -167,9 +187,8 @@ char *_crypt_gensalt_blowfish_rn(unsigned long count, ...@@ -167,9 +187,8 @@ char *_crypt_gensalt_blowfish_rn(unsigned long count,
output[5] = '0' + count % 10; output[5] = '0' + count % 10;
output[6] = '$'; output[6] = '$';
BF_encode(&output[7], (BF_word *)input, 16); BF_encode(&output[7], (BF_word *) input, 16);
output[7 + 22] = '\0'; output[7 + 22] = '\0';
return output; return output;
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* $FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.5 1999/12/17 20:21:45 peter Exp $ * $FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.5 1999/12/17 20:21:45 peter Exp $
* *
*/ */
/* $Id: crypt-md5.c,v 1.1 2001/08/21 01:32:01 momjian Exp $ */ /* $Id: crypt-md5.c,v 1.2 2001/10/25 05:49:19 momjian Exp $ */
#include <postgres.h> #include <postgres.h>
#include "px.h" #include "px.h"
...@@ -23,12 +23,9 @@ ...@@ -23,12 +23,9 @@
char * char *
px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen) px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)
{ {
static char *magic = "$1$"; /* static char *magic = "$1$"; /* This string is magic for this
* This string is magic for * algorithm. Having it this way, we can
* this algorithm. Having * get get better later on */
* it this way, we can get
* get better later on
*/
static char *p; static char *p;
static const char *sp, static const char *sp,
*ep; *ep;
...@@ -99,9 +96,9 @@ px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen) ...@@ -99,9 +96,9 @@ px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)
px_md_finish(ctx, final); px_md_finish(ctx, final);
/* /*
* and now, just to make sure things don't run too fast * and now, just to make sure things don't run too fast On a 60 Mhz
* On a 60 Mhz Pentium this takes 34 msec, so you would * Pentium this takes 34 msec, so you would need 30 seconds to build a
* need 30 seconds to build a 1000 entry dictionary... * 1000 entry dictionary...
*/ */
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
{ {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: internal.c,v 1.5 2001/10/15 19:12:48 tgl Exp $ * $Id: internal.c,v 1.6 2001/10/25 05:49:19 momjian Exp $
*/ */
...@@ -62,10 +62,17 @@ static struct int_digest ...@@ -62,10 +62,17 @@ static struct int_digest
char *name; char *name;
void (*init) (PX_MD * h); void (*init) (PX_MD * h);
} int_digest_list[] = } int_digest_list[] =
{ {
{ "md5", init_md5 }, {
{ "sha1", init_sha1 }, "md5", init_md5
{ NULL, NULL } },
{
"sha1", init_sha1
},
{
NULL, NULL
}
}; };
/* MD5 */ /* MD5 */
...@@ -83,7 +90,7 @@ int_md5_block_len(PX_MD * h) ...@@ -83,7 +90,7 @@ int_md5_block_len(PX_MD * h)
} }
static void static void
int_md5_update(PX_MD * h, const uint8 * data, uint dlen) int_md5_update(PX_MD * h, const uint8 *data, uint dlen)
{ {
MD5_CTX *ctx = (MD5_CTX *) h->p.ptr; MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
...@@ -99,7 +106,7 @@ int_md5_reset(PX_MD * h) ...@@ -99,7 +106,7 @@ int_md5_reset(PX_MD * h)
} }
static void static void
int_md5_finish(PX_MD * h, uint8 * dst) int_md5_finish(PX_MD * h, uint8 *dst)
{ {
MD5_CTX *ctx = (MD5_CTX *) h->p.ptr; MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
...@@ -130,7 +137,7 @@ int_sha1_block_len(PX_MD * h) ...@@ -130,7 +137,7 @@ int_sha1_block_len(PX_MD * h)
} }
static void static void
int_sha1_update(PX_MD * h, const uint8 * data, uint dlen) int_sha1_update(PX_MD * h, const uint8 *data, uint dlen)
{ {
SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr; SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
...@@ -146,7 +153,7 @@ int_sha1_reset(PX_MD * h) ...@@ -146,7 +153,7 @@ int_sha1_reset(PX_MD * h)
} }
static void static void
int_sha1_finish(PX_MD * h, uint8 * dst) int_sha1_finish(PX_MD * h, uint8 *dst)
{ {
SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr; SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
...@@ -209,10 +216,12 @@ init_sha1(PX_MD * md) ...@@ -209,10 +216,12 @@ init_sha1(PX_MD * md)
#define INT_MAX_KEY (512/8) #define INT_MAX_KEY (512/8)
#define INT_MAX_IV (128/8) #define INT_MAX_IV (128/8)
struct int_ctx { struct int_ctx
{
uint8 keybuf[INT_MAX_KEY]; uint8 keybuf[INT_MAX_KEY];
uint8 iv[INT_MAX_IV]; uint8 iv[INT_MAX_IV];
union { union
{
blf_ctx bf; blf_ctx bf;
rijndael_ctx rj; rijndael_ctx rj;
} ctx; } ctx;
...@@ -221,10 +230,13 @@ struct int_ctx { ...@@ -221,10 +230,13 @@ struct int_ctx {
int mode; int mode;
}; };
static void intctx_free(PX_Cipher *c) static void
intctx_free(PX_Cipher * c)
{ {
struct int_ctx *cx = (struct int_ctx *)c->ptr; struct int_ctx *cx = (struct int_ctx *) c->ptr;
if (cx) {
if (cx)
{
memset(cx, 0, sizeof *cx); memset(cx, 0, sizeof *cx);
px_free(cx); px_free(cx);
} }
...@@ -238,53 +250,60 @@ static void intctx_free(PX_Cipher *c) ...@@ -238,53 +250,60 @@ static void intctx_free(PX_Cipher *c)
#define MODE_ECB 0 #define MODE_ECB 0
#define MODE_CBC 1 #define MODE_CBC 1
static uint rj_block_size(PX_Cipher *c) static uint
rj_block_size(PX_Cipher * c)
{ {
return 128/8; return 128 / 8;
} }
static uint rj_key_size(PX_Cipher *c) static uint
rj_key_size(PX_Cipher * c)
{ {
return 256/8; return 256 / 8;
} }
static uint rj_iv_size(PX_Cipher *c) static uint
rj_iv_size(PX_Cipher * c)
{ {
return 128/8; return 128 / 8;
} }
static int rj_init(PX_Cipher *c, const uint8 *key, uint klen, const uint8 *iv) static int
rj_init(PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv)
{ {
struct int_ctx *cx = (struct int_ctx *)c->ptr; struct int_ctx *cx = (struct int_ctx *) c->ptr;
if (klen <= 128/8) if (klen <= 128 / 8)
cx->keylen = 128/8; cx->keylen = 128 / 8;
else if (klen <= 192/8) else if (klen <= 192 / 8)
cx->keylen = 192/8; cx->keylen = 192 / 8;
else if (klen <= 256/8) else if (klen <= 256 / 8)
cx->keylen = 256/8; cx->keylen = 256 / 8;
else else
return -1; return -1;
memcpy(&cx->keybuf, key, klen); memcpy(&cx->keybuf, key, klen);
if (iv) if (iv)
memcpy(cx->iv, iv, 128/8); memcpy(cx->iv, iv, 128 / 8);
return 0; return 0;
} }
static int rj_real_init(struct int_ctx *cx, int dir) static int
rj_real_init(struct int_ctx * cx, int dir)
{ {
aes_set_key(&cx->ctx.rj, cx->keybuf, cx->keylen*8, dir); aes_set_key(&cx->ctx.rj, cx->keybuf, cx->keylen * 8, dir);
return 0; return 0;
} }
static int rj_encrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) static int
rj_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
{ {
struct int_ctx *cx = (struct int_ctx *)c->ptr; struct int_ctx *cx = (struct int_ctx *) c->ptr;
if (!cx->is_init) { if (!cx->is_init)
{
if (rj_real_init(cx, 1)) if (rj_real_init(cx, 1))
return -1; return -1;
} }
...@@ -292,23 +311,26 @@ static int rj_encrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) ...@@ -292,23 +311,26 @@ static int rj_encrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res)
if (dlen == 0) if (dlen == 0)
return 0; return 0;
if ((dlen & 15) || (((unsigned)res) & 3)) if ((dlen & 15) || (((unsigned) res) & 3))
return -1; return -1;
memcpy(res, data, dlen); memcpy(res, data, dlen);
if (cx->mode == MODE_CBC) { if (cx->mode == MODE_CBC)
{
aes_cbc_encrypt(&cx->ctx.rj, cx->iv, res, dlen); aes_cbc_encrypt(&cx->ctx.rj, cx->iv, res, dlen);
memcpy(cx->iv, res + dlen - 16, 16); memcpy(cx->iv, res + dlen - 16, 16);
} else }
else
aes_ecb_encrypt(&cx->ctx.rj, res, dlen); aes_ecb_encrypt(&cx->ctx.rj, res, dlen);
return 0; return 0;
} }
static int rj_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) static int
rj_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
{ {
struct int_ctx *cx = (struct int_ctx *)c->ptr; struct int_ctx *cx = (struct int_ctx *) c->ptr;
if (!cx->is_init) if (!cx->is_init)
if (rj_real_init(cx, 0)) if (rj_real_init(cx, 0))
...@@ -317,15 +339,17 @@ static int rj_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) ...@@ -317,15 +339,17 @@ static int rj_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res)
if (dlen == 0) if (dlen == 0)
return 0; return 0;
if ((dlen & 15) || (((unsigned)res) & 3)) if ((dlen & 15) || (((unsigned) res) & 3))
return -1; return -1;
memcpy(res, data, dlen); memcpy(res, data, dlen);
if (cx->mode == MODE_CBC) { if (cx->mode == MODE_CBC)
{
aes_cbc_decrypt(&cx->ctx.rj, cx->iv, res, dlen); aes_cbc_decrypt(&cx->ctx.rj, cx->iv, res, dlen);
memcpy(cx->iv, data + dlen - 16, 16); memcpy(cx->iv, data + dlen - 16, 16);
} else }
else
aes_ecb_decrypt(&cx->ctx.rj, res, dlen); aes_ecb_decrypt(&cx->ctx.rj, res, dlen);
return 0; return 0;
...@@ -335,7 +359,8 @@ static int rj_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) ...@@ -335,7 +359,8 @@ static int rj_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res)
* initializers * initializers
*/ */
static PX_Cipher * rj_load(int mode) static PX_Cipher *
rj_load(int mode)
{ {
PX_Cipher *c; PX_Cipher *c;
struct int_ctx *cx; struct int_ctx *cx;
...@@ -363,24 +388,28 @@ static PX_Cipher * rj_load(int mode) ...@@ -363,24 +388,28 @@ static PX_Cipher * rj_load(int mode)
* blowfish * blowfish
*/ */
static uint bf_block_size(PX_Cipher *c) static uint
bf_block_size(PX_Cipher * c)
{ {
return 8; return 8;
} }
static uint bf_key_size(PX_Cipher *c) static uint
bf_key_size(PX_Cipher * c)
{ {
return BLF_MAXKEYLEN; return BLF_MAXKEYLEN;
} }
static uint bf_iv_size(PX_Cipher *c) static uint
bf_iv_size(PX_Cipher * c)
{ {
return 8; return 8;
} }
static int bf_init(PX_Cipher *c, const uint8 *key, uint klen, const uint8 *iv) static int
bf_init(PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv)
{ {
struct int_ctx *cx = (struct int_ctx *)c->ptr; struct int_ctx *cx = (struct int_ctx *) c->ptr;
blf_key(&cx->ctx.bf, key, klen); blf_key(&cx->ctx.bf, key, klen);
if (iv) if (iv)
...@@ -389,18 +418,20 @@ static int bf_init(PX_Cipher *c, const uint8 *key, uint klen, const uint8 *iv) ...@@ -389,18 +418,20 @@ static int bf_init(PX_Cipher *c, const uint8 *key, uint klen, const uint8 *iv)
return 0; return 0;
} }
static int bf_encrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) static int
bf_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
{ {
struct int_ctx *cx = (struct int_ctx *)c->ptr; struct int_ctx *cx = (struct int_ctx *) c->ptr;
if (dlen == 0) if (dlen == 0)
return 0; return 0;
if ((dlen & 7) || (((unsigned)res) & 3)) if ((dlen & 7) || (((unsigned) res) & 3))
return -1; return -1;
memcpy(res, data, dlen); memcpy(res, data, dlen);
switch (cx->mode) { switch (cx->mode)
{
case MODE_ECB: case MODE_ECB:
blf_ecb_encrypt(&cx->ctx.bf, res, dlen); blf_ecb_encrypt(&cx->ctx.bf, res, dlen);
break; break;
...@@ -411,18 +442,20 @@ static int bf_encrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) ...@@ -411,18 +442,20 @@ static int bf_encrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res)
return 0; return 0;
} }
static int bf_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) static int
bf_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
{ {
struct int_ctx *cx = (struct int_ctx *)c->ptr; struct int_ctx *cx = (struct int_ctx *) c->ptr;
if (dlen == 0) if (dlen == 0)
return 0; return 0;
if ((dlen & 7) || (((unsigned)res) & 3)) if ((dlen & 7) || (((unsigned) res) & 3))
return -1; return -1;
memcpy(res, data, dlen); memcpy(res, data, dlen);
switch (cx->mode) { switch (cx->mode)
{
case MODE_ECB: case MODE_ECB:
blf_ecb_decrypt(&cx->ctx.bf, res, dlen); blf_ecb_decrypt(&cx->ctx.bf, res, dlen);
break; break;
...@@ -433,7 +466,8 @@ static int bf_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res) ...@@ -433,7 +466,8 @@ static int bf_decrypt(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res)
return 0; return 0;
} }
static PX_Cipher * bf_load(int mode) static PX_Cipher *
bf_load(int mode)
{ {
PX_Cipher *c; PX_Cipher *c;
struct int_ctx *cx; struct int_ctx *cx;
...@@ -458,47 +492,64 @@ static PX_Cipher * bf_load(int mode) ...@@ -458,47 +492,64 @@ static PX_Cipher * bf_load(int mode)
/* ciphers */ /* ciphers */
static PX_Cipher * rj_128_ecb() static PX_Cipher *
rj_128_ecb()
{ {
return rj_load(MODE_ECB); return rj_load(MODE_ECB);
} }
static PX_Cipher * rj_128_cbc() static PX_Cipher *
rj_128_cbc()
{ {
return rj_load(MODE_CBC); return rj_load(MODE_CBC);
} }
static PX_Cipher * bf_ecb_load() static PX_Cipher *
bf_ecb_load()
{ {
return bf_load(MODE_ECB); return bf_load(MODE_ECB);
} }
static PX_Cipher * bf_cbc_load() static PX_Cipher *
bf_cbc_load()
{ {
return bf_load(MODE_CBC); return bf_load(MODE_CBC);
} }
static struct { static struct
{
char *name; char *name;
PX_Cipher *(*load)(void); PX_Cipher *(*load) (void);
} int_ciphers [] = { } int_ciphers[] =
{ "bf-cbc", bf_cbc_load },
{ "bf-ecb", bf_ecb_load }, {
{ "aes-128-cbc", rj_128_cbc }, {
{ "aes-128-ecb", rj_128_ecb }, "bf-cbc", bf_cbc_load
{ NULL, NULL } },
{
"bf-ecb", bf_ecb_load
},
{
"aes-128-cbc", rj_128_cbc
},
{
"aes-128-ecb", rj_128_ecb
},
{
NULL, NULL
}
}; };
static PX_Alias int_aliases [] = { static PX_Alias int_aliases[] = {
{ "bf", "bf-cbc" }, {"bf", "bf-cbc"},
{ "blowfish", "bf-cbc" }, {"blowfish", "bf-cbc"},
{ "aes", "aes-128-cbc" }, {"aes", "aes-128-cbc"},
{ "aes-ecb", "aes-128-ecb" }, {"aes-ecb", "aes-128-ecb"},
{ "aes-cbc", "aes-128-cbc" }, {"aes-cbc", "aes-128-cbc"},
{ "aes-128", "aes-128-cbc" }, {"aes-128", "aes-128-cbc"},
{ "rijndael", "aes-128-cbc" }, {"rijndael", "aes-128-cbc"},
{ "rijndael-128", "aes-128-cbc" }, {"rijndael-128", "aes-128-cbc"},
{ NULL, NULL } {NULL, NULL}
}; };
/* PUBLIC FUNCTIONS */ /* PUBLIC FUNCTIONS */
...@@ -523,7 +574,7 @@ px_find_digest(const char *name, PX_MD ** res) ...@@ -523,7 +574,7 @@ px_find_digest(const char *name, PX_MD ** res)
} }
int int
px_find_cipher(const char *name, PX_Cipher **res) px_find_cipher(const char *name, PX_Cipher ** res)
{ {
int i; int i;
PX_Cipher *c = NULL; PX_Cipher *c = NULL;
...@@ -531,7 +582,8 @@ px_find_cipher(const char *name, PX_Cipher **res) ...@@ -531,7 +582,8 @@ px_find_cipher(const char *name, PX_Cipher **res)
name = px_resolve_alias(int_aliases, name); name = px_resolve_alias(int_aliases, name);
for (i = 0; int_ciphers[i].name; i++) for (i = 0; int_ciphers[i].name; i++)
if (!strcmp(int_ciphers[i].name, name)) { if (!strcmp(int_ciphers[i].name, name))
{
c = int_ciphers[i].load(); c = int_ciphers[i].load();
break; break;
} }
...@@ -542,5 +594,3 @@ px_find_cipher(const char *name, PX_Cipher **res) ...@@ -542,5 +594,3 @@ px_find_cipher(const char *name, PX_Cipher **res)
*res = c; *res = c;
return 0; return 0;
} }
/* $Id: md5.c,v 1.7 2001/10/25 01:29:37 momjian Exp $ */ /* $Id: md5.c,v 1.8 2001/10/25 05:49:19 momjian Exp $ */
/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */ /* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
/* /*
...@@ -132,7 +132,7 @@ static const uint8 md5_paddat[MD5_BUFLEN] = { ...@@ -132,7 +132,7 @@ static const uint8 md5_paddat[MD5_BUFLEN] = {
static void md5_calc(uint8 *, md5_ctxt *); static void md5_calc(uint8 *, md5_ctxt *);
void void
md5_init(md5_ctxt *ctxt) md5_init(md5_ctxt * ctxt)
{ {
ctxt->md5_n = 0; ctxt->md5_n = 0;
ctxt->md5_i = 0; ctxt->md5_i = 0;
...@@ -144,7 +144,7 @@ md5_init(md5_ctxt *ctxt) ...@@ -144,7 +144,7 @@ md5_init(md5_ctxt *ctxt)
} }
void void
md5_loop(md5_ctxt *ctxt, const uint8 *input, unsigned len) md5_loop(md5_ctxt * ctxt, const uint8 *input, unsigned len)
{ {
unsigned int gap, unsigned int gap,
i; i;
...@@ -173,7 +173,7 @@ md5_loop(md5_ctxt *ctxt, const uint8 *input, unsigned len) ...@@ -173,7 +173,7 @@ md5_loop(md5_ctxt *ctxt, const uint8 *input, unsigned len)
} }
void void
md5_pad(md5_ctxt *ctxt) md5_pad(md5_ctxt * ctxt)
{ {
unsigned int gap; unsigned int gap;
...@@ -215,7 +215,7 @@ md5_pad(md5_ctxt *ctxt) ...@@ -215,7 +215,7 @@ md5_pad(md5_ctxt *ctxt)
} }
void void
md5_result(uint8 *digest, md5_ctxt *ctxt) md5_result(uint8 *digest, md5_ctxt * ctxt)
{ {
/* 4 byte words */ /* 4 byte words */
#if BYTE_ORDER == LITTLE_ENDIAN #if BYTE_ORDER == LITTLE_ENDIAN
...@@ -246,7 +246,7 @@ static uint32 X[16]; ...@@ -246,7 +246,7 @@ static uint32 X[16];
#endif #endif
static void static void
md5_calc(uint8 *b64, md5_ctxt *ctxt) md5_calc(uint8 *b64, md5_ctxt * ctxt)
{ {
uint32 A = ctxt->md5_sta; uint32 A = ctxt->md5_sta;
uint32 B = ctxt->md5_stb; uint32 B = ctxt->md5_stb;
......
This diff is collapsed.
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "px-crypt.h" #include "px-crypt.h"
char px_crypt_a64[] = char px_crypt_a64[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/* 0000000000111111111122222222223333333333444444444455555555556666 */ /* 0000000000111111111122222222223333333333444444444455555555556666 */
/* 0123456789012345678901234567890123456789012345678901234567890123 */ /* 0123456789012345678901234567890123456789012345678901234567890123 */
......
This diff is collapsed.
This diff is collapsed.
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: pgcrypto.h,v 1.5 2001/09/23 04:12:44 momjian Exp $ * $Id: pgcrypto.h,v 1.6 2001/10/25 05:49:20 momjian Exp $
*/ */
#ifndef _PG_CRYPTO_H #ifndef _PG_CRYPTO_H
...@@ -45,6 +45,4 @@ Datum pg_decrypt(PG_FUNCTION_ARGS); ...@@ -45,6 +45,4 @@ Datum pg_decrypt(PG_FUNCTION_ARGS);
Datum pg_encrypt_iv(PG_FUNCTION_ARGS); Datum pg_encrypt_iv(PG_FUNCTION_ARGS);
Datum pg_decrypt_iv(PG_FUNCTION_ARGS); Datum pg_decrypt_iv(PG_FUNCTION_ARGS);
Datum pg_cipher_exists(PG_FUNCTION_ARGS); Datum pg_cipher_exists(PG_FUNCTION_ARGS);
#endif #endif
This diff is collapsed.
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: px-crypt.h,v 1.2 2001/09/23 04:12:44 momjian Exp $ * $Id: px-crypt.h,v 1.3 2001/10/25 05:49:20 momjian Exp $
*/ */
#ifndef _PX_CRYPT_H #ifndef _PX_CRYPT_H
...@@ -58,6 +58,7 @@ unsigned px_gen_salt(const char *salt_type, char *dst, int rounds); ...@@ -58,6 +58,7 @@ unsigned px_gen_salt(const char *salt_type, char *dst, int rounds);
/* misc.c */ /* misc.c */
extern void px_crypt_to64(char *s, unsigned long v, int n); extern void px_crypt_to64(char *s, unsigned long v, int n);
extern char px_crypt_a64[]; extern char px_crypt_a64[];
/* avoid conflicts with system libs */ /* avoid conflicts with system libs */
#define _crypt_to64 px_crypt_to64 #define _crypt_to64 px_crypt_to64
#define _crypt_a64 px_crypt_a64 #define _crypt_a64 px_crypt_a64
...@@ -87,6 +88,5 @@ char *px_crypt_des(const char *key, const char *setting); ...@@ -87,6 +88,5 @@ char *px_crypt_des(const char *key, const char *setting);
/* crypt-md5.c */ /* crypt-md5.c */
char *px_crypt_md5(const char *pw, const char *salt, char *px_crypt_md5(const char *pw, const char *salt,
char *dst, unsigned dstlen); char *dst, unsigned dstlen);
#endif /* !PX_SYSTEM_CRYPT */ #endif /* !PX_SYSTEM_CRYPT */
#endif /* _PX_CRYPT_H */ #endif /* _PX_CRYPT_H */
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: px-hmac.c,v 1.1 2001/08/21 01:32:01 momjian Exp $ * $Id: px-hmac.c,v 1.2 2001/10/25 05:49:20 momjian Exp $
*/ */
...@@ -50,7 +50,7 @@ hmac_block_size(PX_HMAC * h) ...@@ -50,7 +50,7 @@ hmac_block_size(PX_HMAC * h)
} }
static void static void
hmac_init(PX_HMAC * h, const uint8 * key, uint klen) hmac_init(PX_HMAC * h, const uint8 *key, uint klen)
{ {
uint bs, uint bs,
hlen, hlen,
...@@ -95,13 +95,13 @@ hmac_reset(PX_HMAC * h) ...@@ -95,13 +95,13 @@ hmac_reset(PX_HMAC * h)
} }
static void static void
hmac_update(PX_HMAC * h, const uint8 * data, uint dlen) hmac_update(PX_HMAC * h, const uint8 *data, uint dlen)
{ {
px_md_update(h->md, data, dlen); px_md_update(h->md, data, dlen);
} }
static void static void
hmac_finish(PX_HMAC * h, uint8 * dst) hmac_finish(PX_HMAC * h, uint8 *dst)
{ {
PX_MD *md = h->md; PX_MD *md = h->md;
uint bs, uint bs,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -27,7 +27,8 @@ typedef int8 s1byte; /* an 8 bit signed character type */ ...@@ -27,7 +27,8 @@ typedef int8 s1byte; /* an 8 bit signed character type */
typedef int16 s2byte; /* a 16 bit signed integer type */ typedef int16 s2byte; /* a 16 bit signed integer type */
typedef int32 s4byte; /* a 32 bit signed integer type */ typedef int32 s4byte; /* a 32 bit signed integer type */
typedef struct _rijndael_ctx { typedef struct _rijndael_ctx
{
u4byte k_len; u4byte k_len;
int decrypt; int decrypt;
u4byte e_key[64]; u4byte e_key[64];
...@@ -41,17 +42,16 @@ typedef struct _rijndael_ctx { ...@@ -41,17 +42,16 @@ typedef struct _rijndael_ctx {
/* require endian conversions for big-endian architectures */ /* require endian conversions for big-endian architectures */
rijndael_ctx * rijndael_ctx *
rijndael_set_key (rijndael_ctx *, const u4byte *, const u4byte, int); rijndael_set_key(rijndael_ctx *, const u4byte *, const u4byte, int);
void rijndael_encrypt (rijndael_ctx *, const u4byte *, u4byte *); void rijndael_encrypt(rijndael_ctx *, const u4byte *, u4byte *);
void rijndael_decrypt (rijndael_ctx *, const u4byte *, u4byte *); void rijndael_decrypt(rijndael_ctx *, const u4byte *, u4byte *);
/* conventional interface */ /* conventional interface */
void aes_set_key(rijndael_ctx * ctx, const uint8 *key, uint keybits, int enc); void aes_set_key(rijndael_ctx * ctx, const uint8 *key, uint keybits, int enc);
void aes_ecb_encrypt(rijndael_ctx *ctx, uint8 *data, unsigned len); void aes_ecb_encrypt(rijndael_ctx * ctx, uint8 *data, unsigned len);
void aes_ecb_decrypt(rijndael_ctx *ctx, uint8 *data, unsigned len); void aes_ecb_decrypt(rijndael_ctx * ctx, uint8 *data, unsigned len);
void aes_cbc_encrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len); void aes_cbc_encrypt(rijndael_ctx * ctx, uint8 *iva, uint8 *data, unsigned len);
void aes_cbc_decrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len); void aes_cbc_decrypt(rijndael_ctx * ctx, uint8 *iva, uint8 *data, unsigned len);
#endif /* _RIJNDAEL_H_ */ #endif /* _RIJNDAEL_H_ */
This diff is collapsed.
/* $Id: sha1.h,v 1.5 2001/08/21 00:42:41 momjian Exp $ */ /* $Id: sha1.h,v 1.6 2001/10/25 05:49:20 momjian Exp $ */
/* $KAME: sha1.h,v 1.4 2000/02/22 14:01:18 itojun Exp $ */ /* $KAME: sha1.h,v 1.4 2000/02/22 14:01:18 itojun Exp $ */
/* /*
...@@ -71,5 +71,4 @@ typedef struct sha1_ctxt SHA1_CTX; ...@@ -71,5 +71,4 @@ typedef struct sha1_ctxt SHA1_CTX;
#define SHA1Final(x, y) sha1_result((y), (x)) #define SHA1Final(x, y) sha1_result((y), (x))
#define SHA1_RESULTLEN (160/8) #define SHA1_RESULTLEN (160/8)
#endif /* _NETINET6_SHA1_H_ */ #endif /* _NETINET6_SHA1_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -25,6 +25,4 @@ ...@@ -25,6 +25,4 @@
#define FILEPATH 19 #define FILEPATH 19
extern const char *descr[]; extern const char *descr[];
#endif #endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment