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

Side by Side Diff: Source/wtf/CryptographicallyRandomNumber.cpp

Issue 15861022: Build WTF as dll in component build (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix AutoDrainedPool ctor and ThreadSpecificThreadExit exports Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/CryptographicallyRandomNumber.h ('k') | Source/wtf/CurrentTime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 1996, David Mazieres <dm@uun.org> 2 * Copyright (c) 1996, David Mazieres <dm@uun.org>
3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
4 * 4 *
5 * Permission to use, copy, modify, and distribute this software for any 5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above 6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies. 7 * copyright notice and this permission notice appear in all copies.
8 * 8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
(...skipping 12 matching lines...) Expand all
23 * compatible with RSA Labs "RC4" cipher (the actual description of 23 * compatible with RSA Labs "RC4" cipher (the actual description of
24 * which is a trade secret). The same algorithm is used as a stream 24 * which is a trade secret). The same algorithm is used as a stream
25 * cipher called "arcfour" in Tatu Ylonen's ssh package. 25 * cipher called "arcfour" in Tatu Ylonen's ssh package.
26 * 26 *
27 * RC4 is a registered trademark of RSA Laboratories. 27 * RC4 is a registered trademark of RSA Laboratories.
28 */ 28 */
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "CryptographicallyRandomNumber.h" 31 #include "CryptographicallyRandomNumber.h"
32 32
33 #include "OSRandomSource.h"
34 #include "StdLibExtras.h" 33 #include "StdLibExtras.h"
35 #include "ThreadingPrimitives.h" 34 #include "ThreadingPrimitives.h"
36 35
37 namespace WTF { 36 namespace WTF {
38 37
38 static RandomNumberSource sourceFunction;
39
40 void setRandomSource(RandomNumberSource source)
41 {
42 sourceFunction = source;
43 }
44
39 namespace { 45 namespace {
40 46
41 class ARC4Stream { 47 class ARC4Stream {
42 public: 48 public:
43 ARC4Stream(); 49 ARC4Stream();
44 50
45 uint8_t i; 51 uint8_t i;
46 uint8_t j; 52 uint8_t j;
47 uint8_t s[256]; 53 uint8_t s[256];
48 }; 54 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 m_stream.s[m_stream.i] = m_stream.s[m_stream.j]; 96 m_stream.s[m_stream.i] = m_stream.s[m_stream.j];
91 m_stream.s[m_stream.j] = si; 97 m_stream.s[m_stream.j] = si;
92 } 98 }
93 m_stream.j = m_stream.i; 99 m_stream.j = m_stream.i;
94 } 100 }
95 101
96 void ARC4RandomNumberGenerator::stir() 102 void ARC4RandomNumberGenerator::stir()
97 { 103 {
98 unsigned char randomness[128]; 104 unsigned char randomness[128];
99 size_t length = sizeof(randomness); 105 size_t length = sizeof(randomness);
100 cryptographicallyRandomValuesFromOS(randomness, length); 106 (*sourceFunction)(randomness, length);
101 addRandomData(randomness, length); 107 addRandomData(randomness, length);
102 108
103 // Discard early keystream, as per recommendations in: 109 // Discard early keystream, as per recommendations in:
104 // http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps 110 // http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
105 for (int i = 0; i < 256; i++) 111 for (int i = 0; i < 256; i++)
106 getByte(); 112 getByte();
107 m_count = 1600000; 113 m_count = 1600000;
108 } 114 }
109 115
110 void ARC4RandomNumberGenerator::stirIfNeeded() 116 void ARC4RandomNumberGenerator::stirIfNeeded()
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 163 }
158 164
159 ARC4RandomNumberGenerator& sharedRandomNumberGenerator() 165 ARC4RandomNumberGenerator& sharedRandomNumberGenerator()
160 { 166 {
161 DEFINE_STATIC_LOCAL(ARC4RandomNumberGenerator, randomNumberGenerator, ()); 167 DEFINE_STATIC_LOCAL(ARC4RandomNumberGenerator, randomNumberGenerator, ());
162 return randomNumberGenerator; 168 return randomNumberGenerator;
163 } 169 }
164 170
165 } 171 }
166 172
173
167 uint32_t cryptographicallyRandomNumber() 174 uint32_t cryptographicallyRandomNumber()
168 { 175 {
169 return sharedRandomNumberGenerator().randomNumber(); 176 return sharedRandomNumberGenerator().randomNumber();
170 } 177 }
171 178
172 void cryptographicallyRandomValues(void* buffer, size_t length) 179 void cryptographicallyRandomValues(void* buffer, size_t length)
173 { 180 {
174 sharedRandomNumberGenerator().randomValues(buffer, length); 181 sharedRandomNumberGenerator().randomValues(buffer, length);
175 } 182 }
176 183
177 } 184 }
OLDNEW
« no previous file with comments | « Source/wtf/CryptographicallyRandomNumber.h ('k') | Source/wtf/CurrentTime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698