19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#import "LegacyPasswordGenerator.h"
@implementation LegacyPasswordGenerator
@synthesize site = _site, passphrase = _passphrase, output = _output;
+ (instancetype)generator
{
return [[[self alloc] init] autorelease];
}
- init
|
|
>
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#import "LegacyPasswordGenerator.h"
@implementation LegacyPasswordGenerator
@synthesize site = _site, keyfile = _keyfile, passphrase = _passphrase;
@synthesize output = _output;
+ (instancetype)generator
{
return [[[self alloc] init] autorelease];
}
- init
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
{
return _length;
}
- (void)derivePassword
{
OFSHA256Hash *siteHash = [OFSHA256Hash cryptoHash];
[siteHash updateWithBuffer: [_site UTF8String]
length: [_site UTF8StringLength]];
if (_output != NULL) {
of_explicit_memset(_output, 0, _length);
[self freeMemory: _output];
}
_output = [self allocMemoryWithSize: _length + 1];
of_scrypt(8, 524288, 2, [siteHash digest],
[[siteHash class] digestSize], _passphrase, strlen(_passphrase),
_output, _length);
/*
* This has a bias, however, this is what scrypt-genpass does and the
* legacy mode wants to be compatible to scrypt-genpass.
*/
_output[0] = "abcdefghijklmnopqrstuvwxyz"[_output[0] % 26];
_output[1] = "0123456789"[_output[1] % 10];
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
{
return _length;
}
- (void)derivePassword
{
OFSHA256Hash *siteHash = [OFSHA256Hash cryptoHash];
size_t passphraseLength, combinedPassphraseLength;
char *combinedPassphrase;
[siteHash updateWithBuffer: [_site UTF8String]
length: [_site UTF8StringLength]];
if (_output != NULL) {
of_explicit_memset(_output, 0, _length);
[self freeMemory: _output];
}
_output = [self allocMemoryWithSize: _length + 1];
passphraseLength = combinedPassphraseLength = strlen(_passphrase);
if (_keyfile != nil) {
if (SIZE_MAX - combinedPassphraseLength < [_keyfile count])
@throw [OFOutOfRangeException exception];
combinedPassphraseLength += [_keyfile count];
}
if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: combinedPassphraseLength];
@try {
memcpy(combinedPassphrase, _passphrase, passphraseLength);
if (_keyfile != nil)
memcpy(combinedPassphrase + passphraseLength,
[_keyfile items], [_keyfile count]);
of_scrypt(8, 524288, 2, [siteHash digest],
[[siteHash class] digestSize], combinedPassphrase,
combinedPassphraseLength, _output, _length);
} @finally {
of_explicit_memset(combinedPassphrase, 0,
combinedPassphraseLength);
free(combinedPassphrase);
}
/*
* This has a bias, however, this is what scrypt-genpass does and the
* legacy mode wants to be compatible to scrypt-genpass.
*/
_output[0] = "abcdefghijklmnopqrstuvwxyz"[_output[0] % 26];
_output[1] = "0123456789"[_output[1] % 10];
|