| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/curve25519.h> |
| 16 |
| 17 | #include <errno.h> |
| 18 | #include <stdio.h> |
| 19 | #include <string.h> |
| 20 |
| 21 | #include "internal.h" |
| 22 |
| 23 |
| 24 | static const struct argument kArguments[] = { |
| 25 | { |
| 26 | "-out-public", kRequiredArgument, "The file to write the public key to", |
| 27 | }, |
| 28 | { |
| 29 | "-out-private", kRequiredArgument, |
| 30 | "The file to write the private key to", |
| 31 | }, |
| 32 | { |
| 33 | "", kOptionalArgument, "", |
| 34 | }, |
| 35 | }; |
| 36 |
| 37 | bool GenerateEd25519Key(const std::vector<std::string> &args) { |
| 38 | std::map<std::string, std::string> args_map; |
| 39 |
| 40 | if (!ParseKeyValueArguments(&args_map, args, kArguments)) { |
| 41 | PrintUsage(kArguments); |
| 42 | return false; |
| 43 | } |
| 44 |
| 45 | uint8_t public_key[32], private_key[64]; |
| 46 | ED25519_keypair(public_key, private_key); |
| 47 |
| 48 | return WriteToFile(args_map["-out-public"], public_key) && |
| 49 | WriteToFile(args_map["-out-private"], private_key); |
| 50 | } |
| 51 |