Deleted Added
full compact
crypt-md5.c (93157) crypt-md5.c (115733)
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
1/*-
2 * Copyright (c) 2003 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
8 */
9
10#include <sys/cdefs.h>
25 */
26
27#include <sys/cdefs.h>
11__FBSDID("$FreeBSD: head/lib/libcrypt/crypt-md5.c 93157 2002-03-25 15:55:36Z phk $");
28__FBSDID("$FreeBSD: head/lib/libcrypt/crypt-md5.c 115733 2003-06-02 21:43:14Z markm $");
12
29
13#include <unistd.h>
30#include <sys/types.h>
31
32#include <err.h>
33#include <md5.h>
14#include <stdio.h>
15#include <string.h>
34#include <stdio.h>
35#include <string.h>
16#include <md5.h>
17#include <err.h>
36#include <unistd.h>
37
18#include "crypt.h"
19
20/*
21 * UNIX password
22 */
23
24char *
25crypt_md5(const char *pw, const char *salt)
26{
27 MD5_CTX ctx,ctx1;
28 unsigned long l;
29 int sl, pl;
30 u_int i;
31 u_char final[MD5_SIZE];
32 static const char *sp, *ep;
33 static char passwd[120], *p;
38#include "crypt.h"
39
40/*
41 * UNIX password
42 */
43
44char *
45crypt_md5(const char *pw, const char *salt)
46{
47 MD5_CTX ctx,ctx1;
48 unsigned long l;
49 int sl, pl;
50 u_int i;
51 u_char final[MD5_SIZE];
52 static const char *sp, *ep;
53 static char passwd[120], *p;
34 static const char *magic = "$1$"; /*
35 * This string is magic for
36 * this algorithm. Having
37 * it this way, we can get
38 * better later on.
39 */
54 static const char *magic = "$1$";
40
41 /* Refine the Salt first */
42 sp = salt;
43
44 /* If it starts with the magic string, then skip that */
45 if(!strncmp(sp, magic, strlen(magic)))
46 sp += strlen(magic);
47

--- 74 unchanged lines hidden (view full) ---

122 l = (final[ 1]<<16) | (final[ 7]<<8) | final[13];
123 _crypt_to64(p, l, 4); p += 4;
124 l = (final[ 2]<<16) | (final[ 8]<<8) | final[14];
125 _crypt_to64(p, l, 4); p += 4;
126 l = (final[ 3]<<16) | (final[ 9]<<8) | final[15];
127 _crypt_to64(p, l, 4); p += 4;
128 l = (final[ 4]<<16) | (final[10]<<8) | final[ 5];
129 _crypt_to64(p, l, 4); p += 4;
55
56 /* Refine the Salt first */
57 sp = salt;
58
59 /* If it starts with the magic string, then skip that */
60 if(!strncmp(sp, magic, strlen(magic)))
61 sp += strlen(magic);
62

--- 74 unchanged lines hidden (view full) ---

137 l = (final[ 1]<<16) | (final[ 7]<<8) | final[13];
138 _crypt_to64(p, l, 4); p += 4;
139 l = (final[ 2]<<16) | (final[ 8]<<8) | final[14];
140 _crypt_to64(p, l, 4); p += 4;
141 l = (final[ 3]<<16) | (final[ 9]<<8) | final[15];
142 _crypt_to64(p, l, 4); p += 4;
143 l = (final[ 4]<<16) | (final[10]<<8) | final[ 5];
144 _crypt_to64(p, l, 4); p += 4;
130 l = final[11] ;
145 l = final[11];
131 _crypt_to64(p, l, 2); p += 2;
132 *p = '\0';
133
134 /* Don't leave anything around in vm they could use. */
135 memset(final, 0, sizeof(final));
136
146 _crypt_to64(p, l, 2); p += 2;
147 *p = '\0';
148
149 /* Don't leave anything around in vm they could use. */
150 memset(final, 0, sizeof(final));
151
137 return passwd;
152 return (passwd);
138}
153}
139