Replace current verbose GPL stuff in libbb/*.c with one-line GPL boilerplate.
[oweals/busybox.git] / libbb / pw_encrypt.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Utility routine.
4  *
5  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8  */
9
10 #include "libbb.h"
11 #include <string.h>
12 #include <crypt.h>
13
14
15 char *pw_encrypt(const char *clear, const char *salt)
16 {
17         static char cipher[128];
18         char *cp;
19
20 #ifdef CONFIG_FEATURE_SHA1_PASSWORDS
21         if (strncmp(salt, "$2$", 3) == 0) {
22                 return sha1_crypt(clear);
23         }
24 #endif
25         cp = (char *) crypt(clear, salt);
26         /* if crypt (a nonstandard crypt) returns a string too large,
27            truncate it so we don't overrun buffers and hope there is
28            enough security in what's left */
29         safe_strncpy(cipher, cp, sizeof(cipher));
30         return cipher;
31 }
32