Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: src/platform/cryptohome/username_passhash.cc

Issue 2051003: Initial patch from Will. (Closed) Base URL: ssh://git@chromiumos-git/chromiumos
Patch Set: Address style nits. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cryptohome/username_passhash.h"
6
7 #include <openssl/sha.h>
8
9 #include "base/logging.h"
10 #include "chromeos/utility.h"
11
12 namespace cryptohome {
13 using namespace chromeos;
14 using std::string;
15
16 UsernamePasshash::UsernamePasshash(const char *username,
17 const int username_length,
18 const char *passhash,
19 const int passhash_length)
20 : username_(username, username_length),
21 passhash_(passhash, passhash_length) {
22 }
23
24 void UsernamePasshash::GetFullUsername(char *name_buffer, int length) const {
25 strncpy(name_buffer, username_.c_str(), length);
26 }
27
28 void UsernamePasshash::GetPartialUsername(char *name_buffer, int length) const {
29 size_t at_index = username_.find('@');
30 string partial = username_.substr(0, at_index);
31 strncpy(name_buffer, partial.c_str(), length);
32 }
33
34 string UsernamePasshash::GetObfuscatedUsername(const Blob &system_salt) const {
35 CHECK(!username_.empty());
36
37 SHA_CTX ctx;
38 unsigned char md_value[SHA_DIGEST_LENGTH];
39
40 SHA1_Init(&ctx);
41 SHA1_Update(&ctx, &system_salt[0], system_salt.size());
42 SHA1_Update(&ctx, username_.c_str(), username_.length());
43 SHA1_Final(md_value, &ctx);
44
45 Blob md_blob(md_value,
46 md_value + (SHA_DIGEST_LENGTH * sizeof(unsigned char)));
47
48 return AsciiEncode(md_blob);
49 }
50
51 string UsernamePasshash::GetPasswordWeakHash(const Blob &system_salt) const {
52 return passhash_;
53 }
54
55 } // namespace cryptohome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698