sunmd5.c revision 1dbc1fed8be6e82e676ff3f124628dc470058bfb
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <fcntl.h>
#include <unistd.h>
#include <strings.h>
#include <pwd.h>
#include <errno.h>
#include <stdlib.h>
#include <syslog.h>
#include <crypt.h>
#include <md5.h>
#define CRYPT_ALGNAME "md5"
/* minimum number of rounds we do, not including the per-user ones */
#define DIGEST_LEN 16
#define ROUND_BUFFER_LEN 64
/*
* Public domain quotation courtesy of Project Gutenberg.
* Hamlet III.ii - 1517 bytes, including trailing NUL
* ANSI-C string constant concatenation is a requirement here.
*/
static const char constant_phrase[] =
"To be, or not to be,--that is the question:--\n"
"Whether 'tis nobler in the mind to suffer\n"
"The slings and arrows of outrageous fortune\n"
"Or to take arms against a sea of troubles,\n"
"And by opposing end them?--To die,--to sleep,--\n"
"No more; and by a sleep to say we end\n"
"The heartache, and the thousand natural shocks\n"
"That flesh is heir to,--'tis a consummation\n"
"Devoutly to be wish'd. To die,--to sleep;--\n"
"To sleep! perchance to dream:--ay, there's the rub;\n"
"For in that sleep of death what dreams may come,\n"
"When we have shuffled off this mortal coil,\n"
"Must give us pause: there's the respect\n"
"That makes calamity of so long life;\n"
"For who would bear the whips and scorns of time,\n"
"The oppressor's wrong, the proud man's contumely,\n"
"The pangs of despis'd love, the law's delay,\n"
"The insolence of office, and the spurns\n"
"That patient merit of the unworthy takes,\n"
"When he himself might his quietus make\n"
"With a bare bodkin? who would these fardels bear,\n"
"To grunt and sweat under a weary life,\n"
"But that the dread of something after death,--\n"
"The undiscover'd country, from whose bourn\n"
"No traveller returns,--puzzles the will,\n"
"And makes us rather bear those ills we have\n"
"Than fly to others that we know not of?\n"
"Thus conscience does make cowards of us all;\n"
"And thus the native hue of resolution\n"
"Is sicklied o'er with the pale cast of thought;\n"
"And enterprises of great pith and moment,\n"
"With this regard, their currents turn awry,\n"
"And lose the name of action.--Soft you now!\n"
"The fair Ophelia!--Nymph, in thy orisons\n"
"Be all my sins remember'd.\n";
/* ------------------------------------------------------------------ */
static int
{
int byte_off;
int bit_off;
/* return the value of bit N from the digest */
}
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
static void
{
while (--n >= 0) {
*s++ = itoa64[v & 0x3f];
v >>= 6;
}
}
#define ROUNDS "rounds="
/*
* get the integer value after rounds= where ever it occurs in the string.
* if the last char after the int is a , or $ that is fine anything else is an
* error.
*/
static uint32_t
getrounds(const char *s)
{
char *r, *p, *e;
long val;
if (s == NULL)
return (0);
return (0);
}
return (0);
}
p = r + ROUNDSLEN;
errno = 0;
/*
* An error occurred or there is non-numeric stuff at the end
* which isn't one of the crypt(3c) special chars ',' or '$'
*/
!(*e == '\0' || *e == ',' || *e == '$')) {
"crypt_sunmd5: invalid rounds specification \"%s\"", s);
return (0);
}
}
/* ARGSUSED3 */
char *
crypt_gensalt_impl(char *gsbuffer,
const char *oldsalt,
const char **params)
{
uint32_t confrounds = 0;
int i;
int fd;
} else {
"crypt_sunmd5: invalid parameter %s", params[i]);
return (NULL);
}
}
/*
* If the config file has a higher value for rounds= than what
* was in the old salt use that, otherwise keep what was in the
* old salt.
*/
if (confrounds > saltrounds) {
}
goto fail;
}
goto fail;
}
if (saltrounds > 0) {
saltrounds) >= gsbufflen)
goto fail;
} else {
goto fail;
}
goto fail;
goto fail;
return (gsbuffer);
fail:
return (NULL);
}
/*ARGSUSED4*/
char *
crypt_genhash_impl(char *ctbuffer,
const char *plaintext,
const char *salt,
const char **params)
{
int i;
int round;
int maxrounds = BASIC_ROUND_COUNT;
uint32_t l;
char *puresalt;
char *saltend;
char *p;
/* put all the sensitive data in a struct */
struct {
int s7shift; /* shift for shift_7 creation, vals 0..7 */
int indirect_a; /* 7bit index into digest */
int shift_a; /* shift schedule, vals 0..1 */
int indirect_b; /* 7bit index into digest */
int shift_b; /* shift schedule, vals 0..1 */
int bit_a; /* single bit for cointoss */
int bit_b; /* single bit for cointoss */
} data;
/*
* Extract the puresalt (if it exists) from the existing salt string
* $md5[,rounds=%d]$<puresalt>$<optional existing encoding>
*/
return (NULL);
}
return (NULL);
}
} else {
return (NULL);
}
}
/* initialise the context */
/* update with the (hopefully entropic) plaintext */
/* update with the (publically known) salt */
/* compute the digest */
/*
* now to delay high-speed md5 implementations that have stuff
* like code inlining, loops unrolled and table lookup
*/
/* re-initialise the context */
/* update with the previous digest */
/* populate the shift schedules for use later */
for (i = 0; i < 16; i++) {
int j;
/* offset 3 -> occasionally span more than 1 int32 fetch */
j = (i + 3) % 16;
& 0x01;
}
/* populate indirect_4 with 4bit values extracted from digest */
for (i = 0; i < 16; i++) {
/* shift the digest byte and extract four bits */
data.indirect_4[i] =
}
/*
* populate indirect_7 with 7bit values from digest
* indexed via indirect_4
*/
for (i = 0; i < 16; i++) {
/* shift the digest byte and extract seven bits */
}
/*
* use the 7bit values to indirect into digest,
* and create two 8bit values from the results.
*/
for (i = 0; i < 8; i++) {
data.indirect_7[i]) << i);
}
/* shall we utilise the top or bottom 7 bits? */
/* extract two data.digest bits */
#if ALGDEBUG
for (i = 0; i < 15; i++) {
}
for (i = 0; i < 15; i++) {
}
#endif
/* xor a coin-toss; if true, mix-in the constant phrase */
(unsigned char *) constant_phrase,
sizeof (constant_phrase));
#if ALGDEBUG
(void) printf("mixing constant_phrase\n");
#endif
}
/* digest a decimal sprintf of the current roundcount */
}
#if ALGDEBUG
/* print the digest */
for (i = 0; i < 16; i++) {
}
(void) printf("\n");
#endif
*p = '\0';
/* tidy up after ourselves */
return (ctbuffer);
}