• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *   http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <crypt.h>
17 #include "functionalext.h"
18 
test_crypt(void)19 static void test_crypt(void)
20 {
21     char *key = "password";
22     char *salt;
23 
24     salt = "$1$";
25     char *md5_result = crypt(key, salt);
26     char *md5_expect = "5f4dcc3b5aa765d61d8327deb882cf99";
27     EXPECT_EQ(test_crypt, md5_result, md5_expect);
28 
29     salt = "$2$";
30     char *blowfish_result_first = crypt(key, salt);
31     char *blowfish_result_second = crypt(key, salt);
32     EXPECT_EQ(test_crypt, blowfish_result_first, blowfish_result_second);
33 
34     salt = "$5$";
35     char *sha256_result = crypt(key, salt);
36     char *sha256_expect =
37         "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8";
38     EXPECT_EQ(test_crypt, sha256_result, sha256_expect);
39 
40     salt = "$6$";
41     char *sha512_result = crypt(key, salt);
42     char *sha512_expect =
43         "b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d778"
44         "5e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86";
45     EXPECT_EQ(test_crypt, sha512_result, sha512_expect);
46 
47     salt = "";
48     char *des_result_first = crypt(key, salt);
49     char *des_result_second = crypt(key, salt);
50     EXPECT_EQ(test_crypt, des_result_first, des_result_second);
51 }
52 
main(void)53 int main(void)
54 {
55     test_crypt();
56     return t_status;
57 }