2019-04-12 06:36:43 +02:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
2014-07-23 15:03:52 +02:00
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2014-09-27 14:50:15 +02:00
|
|
|
/*!
|
|
|
|
* \file electrum-words.h
|
|
|
|
*
|
|
|
|
* \brief Mnemonic seed generation and wallet restoration from them.
|
|
|
|
*
|
2014-06-05 00:59:47 +02:00
|
|
|
* This file and its cpp file are for translating Electrum-style word lists
|
|
|
|
* into their equivalent byte representations for cross-compatibility with
|
|
|
|
* that method of "backing up" one's wallet keys.
|
|
|
|
*/
|
|
|
|
|
2014-10-02 14:45:18 +02:00
|
|
|
#ifndef ELECTRUM_WORDS_H
|
|
|
|
#define ELECTRUM_WORDS_H
|
|
|
|
|
2014-06-05 00:59:47 +02:00
|
|
|
#include <string>
|
2014-06-06 22:31:04 +02:00
|
|
|
#include <cstdint>
|
2014-06-05 00:59:47 +02:00
|
|
|
#include "crypto/crypto.h" // for declaration of crypto::secret_key
|
|
|
|
|
2018-07-07 01:03:15 +02:00
|
|
|
namespace epee { class wipeable_string; }
|
|
|
|
|
2014-09-27 14:50:15 +02:00
|
|
|
/*!
|
|
|
|
* \namespace crypto
|
2014-09-27 22:59:25 +02:00
|
|
|
*
|
|
|
|
* \brief crypto namespace.
|
2014-09-27 14:50:15 +02:00
|
|
|
*/
|
2014-06-05 00:59:47 +02:00
|
|
|
namespace crypto
|
|
|
|
{
|
2014-09-27 14:50:15 +02:00
|
|
|
/*!
|
2014-09-27 22:59:25 +02:00
|
|
|
* \namespace crypto::ElectrumWords
|
2014-09-27 14:50:15 +02:00
|
|
|
*
|
2014-09-27 22:59:25 +02:00
|
|
|
* \brief Mnemonic seed word generation and wallet restoration helper functions.
|
2014-09-27 14:50:15 +02:00
|
|
|
*/
|
2014-06-05 00:59:47 +02:00
|
|
|
namespace ElectrumWords
|
|
|
|
{
|
2014-10-02 14:45:18 +02:00
|
|
|
|
2014-10-07 21:14:26 +02:00
|
|
|
const int seed_length = 24;
|
2017-04-24 21:27:12 +02:00
|
|
|
const std::string old_language_name = "EnglishOld";
|
2017-11-09 11:56:53 +01:00
|
|
|
/*!
|
|
|
|
* \brief Converts seed words to bytes (secret key).
|
|
|
|
* \param words String containing the words separated by spaces.
|
|
|
|
* \param dst To put the secret data restored from the words.
|
|
|
|
* \param len The number of bytes to expect, 0 if unknown
|
|
|
|
* \param duplicate If true and len is not zero, we accept half the data, and duplicate it
|
|
|
|
* \param language_name Language of the seed as found gets written here.
|
|
|
|
* \return false if not a multiple of 3 words, or if word is not in the words list
|
|
|
|
*/
|
2018-07-07 01:03:15 +02:00
|
|
|
bool words_to_bytes(const epee::wipeable_string &words, epee::wipeable_string& dst, size_t len, bool duplicate,
|
2017-11-09 11:56:53 +01:00
|
|
|
std::string &language_name);
|
2014-09-27 14:50:15 +02:00
|
|
|
/*!
|
|
|
|
* \brief Converts seed words to bytes (secret key).
|
2014-10-02 14:45:18 +02:00
|
|
|
* \param words String containing the words separated by spaces.
|
|
|
|
* \param dst To put the secret key restored from the words.
|
|
|
|
* \param language_name Language of the seed as found gets written here.
|
|
|
|
* \return false if not a multiple of 3 words, or if word is not in the words list
|
2014-09-27 14:50:15 +02:00
|
|
|
*/
|
2018-07-07 01:03:15 +02:00
|
|
|
bool words_to_bytes(const epee::wipeable_string &words, crypto::secret_key& dst,
|
2014-10-02 14:45:18 +02:00
|
|
|
std::string &language_name);
|
2014-09-27 14:50:15 +02:00
|
|
|
|
2017-11-09 11:56:53 +01:00
|
|
|
/*!
|
|
|
|
* \brief Converts bytes to seed words.
|
|
|
|
* \param src Secret data
|
|
|
|
* \param len Secret data length in bytes (positive multiples of 4 only)
|
|
|
|
* \param words Space delimited concatenated words get written here.
|
|
|
|
* \param language_name Seed language name
|
|
|
|
* \return true if successful false if not. Unsuccessful if wrong key size.
|
|
|
|
*/
|
Overhaul and fix crypto::{public_key,ec_point,etc.} types
- Remove implicit `operator bool` from ec_point/public_key/etc. which
was causing all sorts of implicit conversion mess and bugs.
- Change ec_point/public_key/etc. to use a `std::array<unsigned char,
32>` (via a base type) rather than a C-array of char that has to be
reinterpret_cast<>'ed all over the place.
- Add methods to ec_point/public_key/etc. that make it work more like a
container of bytes (`.data()`, `.size()`, `operator[]`, `begin()`,
`end()`).
- Make a generic `crypto::null<T>` that is a constexpr all-0 `T`, rather
than the mishmash `crypto::null_hash`, crypto::null_pkey,
crypto::hash::null(), and so on.
- Replace three metric tons of `crypto::hash blahblah =
crypto::null_hash;` with the much simpler `crypto::hash blahblah{};`,
because there's no need to make a copy of a null hash in all these
cases. (Likewise for a few other null_whatevers).
- Remove a whole bunch of `if (blahblah == crypto::null_hash)` and `if
(blahblah != crypto::null_hash)` with the more concise `if
(!blahblah)` and `if (blahblah)` (which are fine via the newly
*explicit* bool conversion operators).
- `crypto::signature` becomes a 64-byte container (as above) but with
`c()` and `r()` to get the c() and r() data pointers. (Previously
`.c` and `.r` were `ec_scalar`s).
- Delete with great prejudice CRYPTO_MAKE_COMPARABLE and
CRYPTO_MAKE_HASHABLE and all the other utter trash in
`crypto/generic-ops.h`.
- De-inline functions in very common crypto/*.h files so that they don't
have to get compiled 300 times.
- Remove the disgusting include-a-C-header-inside-a-C++-namespace
garbage from some crypto headers trying to be both a C and *different*
C++ header at once.
- Remove the toxic, disgusting, shameful `operator&` on ec_scalar, etc.
that replace `&x` with `reinterpret_cast x into an unsigned char*`.
This was pure toxic waste.
- changed some `<<` outputs to fmt
- Random other small changes encountered while fixing everything that
cascaded out of the above changes.
2022-10-15 03:22:44 +02:00
|
|
|
bool bytes_to_words(const unsigned char *src, size_t len, epee::wipeable_string& words,
|
2017-11-09 11:56:53 +01:00
|
|
|
const std::string &language_name);
|
|
|
|
|
2014-09-27 14:50:15 +02:00
|
|
|
/*!
|
|
|
|
* \brief Converts bytes (secret key) to seed words.
|
2014-10-02 14:45:18 +02:00
|
|
|
* \param src Secret key
|
|
|
|
* \param words Space delimited concatenated words get written here.
|
|
|
|
* \param language_name Seed language name
|
|
|
|
* \return true if successful false if not. Unsuccessful if wrong key size.
|
2014-09-27 14:50:15 +02:00
|
|
|
*/
|
2018-07-07 01:03:15 +02:00
|
|
|
bool bytes_to_words(const crypto::secret_key& src, epee::wipeable_string& words,
|
2014-10-02 14:45:18 +02:00
|
|
|
const std::string &language_name);
|
2014-09-27 14:50:15 +02:00
|
|
|
|
2022-04-07 05:50:14 +02:00
|
|
|
/*!
|
|
|
|
* \brief Converts bytes (secret key) to seed words.
|
|
|
|
* \param src Secret key
|
|
|
|
* \param language_name Seed language name
|
|
|
|
* \return Space delimited concatenated words get written here.
|
|
|
|
*/
|
|
|
|
std::string bytes_to_words(const crypto::secret_key& src, const std::string &language_name);
|
|
|
|
|
2014-09-27 14:50:15 +02:00
|
|
|
/*!
|
|
|
|
* \brief Gets a list of seed languages that are supported.
|
2014-10-02 18:05:27 +02:00
|
|
|
* \param languages A vector is set to the list of languages.
|
2018-03-17 23:46:41 +01:00
|
|
|
* \param english whether to get the names in English or the language language
|
2014-09-27 14:50:15 +02:00
|
|
|
*/
|
2018-03-17 23:46:41 +01:00
|
|
|
void get_language_list(std::vector<std::string> &languages, bool english = false);
|
2014-09-27 14:50:15 +02:00
|
|
|
|
2014-09-27 22:59:25 +02:00
|
|
|
/*!
|
|
|
|
* \brief Tells if the seed passed is an old style seed or not.
|
|
|
|
* \param seed The seed to check (a space delimited concatenated word list)
|
|
|
|
* \return true if the seed passed is a old style seed false if not.
|
2014-09-27 14:50:15 +02:00
|
|
|
*/
|
2018-07-07 01:03:15 +02:00
|
|
|
bool get_is_old_style_seed(const epee::wipeable_string &seed);
|
2018-03-17 23:46:41 +01:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the name of a language in English
|
|
|
|
* \param name the name of the language in its own language
|
|
|
|
* \return the name of the language in English
|
|
|
|
*/
|
|
|
|
std::string get_english_name_for(const std::string &name);
|
2014-06-05 00:59:47 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-02 14:45:18 +02:00
|
|
|
|
|
|
|
#endif
|