Is there some step-by-step guide on how the official client encrypts the wallet? I'm trying to write an implementation of that in Go, but can't seem to find any concrete reference, asides

https://github.com/bitcoin/bitcoin/blob/6b8a5ab622e5c9386c872036646bf94da983b190/doc/READMESo lets see if I got this right...

I have a private key:

18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

And a password:

Satoshi

Then I need a random master key (how long is it? Is it stored anywhere?)

??

I take a SHA-512 of the password

B85729C8DB06F82DDEDBF5B70B482D32C46A556562FE79AD8402820D52EB7D562463C021F23E33D

6274E60845C19D6DC298910537D8D3C1CB4DB08F88D2E8B21

Then I perform OpenSSL's EVP_BytesToKey from the master key and the SHA in a dynamic number of rounds based on the speed of my computer (how do I calculate this?)

And what I get is the encrypted private key, right?