<commit_before>//  File : keys.h
//  Author: <NAME> <<EMAIL>>
//
//  Description: Cryptographic key utilities for the Tao.
//
//  Copyright (c) 2014, <NAME>.  All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef TAO_KEYS_H_
#define TAO_KEYS_H_

#include <string>

#include <keyczar/base/basictypes.h>  // DISALLOW_COPY_AND_ASSIGN
#include <keyczar/base/scoped_ptr.h>
#include <openssl/bio.h>
#include <openssl/dsa.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>

#include "tao/keys.pb.h"
#include "tao/tao.h"
#include "tao/util.h"

namespace keyczar {
class Signer;
class Crypter;
class Verifier;
}  // namespace keyczar

namespace tao {
using std::string;

/// A smart pointer to an OpenSSL X509 structure.
typedef scoped_ptr_malloc<X509, CallUnlessNull<X509, X509_free>> ScopedX509;

/// A smart pointer to an OpenSSL EVP_PKEY object.
typedef scoped_ptr_malloc<EVP_PKEY, CallUnlessNull<EVP_PKEY, EVP_PKEY_free>>
    ScopedEvpPkey;

/// A smart pointer to an OpenSSL EC_KEY object.
typedef scoped_ptr_malloc<EC_KEY, CallUnlessNull<EC_KEY, EC_KEY_free>>
    ScopedECKey;

/// A smart pointer to an OpenSSL RSA object.
typedef scoped_ptr_malloc<RSA, CallUnlessNull<RSA, RSA_free>> ScopedRsa;

/// A smart pointer to an OpenSSL BIO object.
typedef scoped_ptr_malloc<BIO, CallUnlessNull<BIO, BIO_free_all>> ScopedBio;

/// Load a clear-text ECDSA verifier key.
/// @param path The location of the key on disk.
/// @param[in,out] key A scoped Verifier to fill with the key.
/// TODO(kwalsh) Eventually, this function should be removed.
bool LoadVerifierKey(const string &path, scoped_ptr<keyczar::Verifier> *key);

/// Load a password-protected ECDSA signing private key.
/// @param path path The location of the key on disk.
/// @param password The password used to encrypt the key on disk.
/// TODO(kwalsh) Eventually, this function should be removed.
bool LoadSigningKey(const string &path, const string &password,<commit_msg>start of removing keyczar<commit_after>//  File : keys.h
//  Author: <NAME> <<EMAIL>>
//
//  Description: Cryptographic key utilities for the Tao.
//
//  Copyright (c) 2014, <NAME>.  All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef TAO_KEYS_H_
#define TAO_KEYS_H_

#include <string>

#include <keyczar/base/basictypes.h>  // DISALLOW_COPY_AND_ASSIGN
#include <keyczar/base/scoped_ptr.h>
#include <openssl/bio.h>
#include <openssl/dsa.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>

#include "tao/keys.pb.h"
#include "tao/tao.h"
#include "tao/util.h"

namespace keyczar {
class Signer;
class Crypter;
class Verifier;
}  // namespace keyczar

// Eliminating keyczar
// Signer:
//   Generate(type=ECDSA_PAIR, purpose=sign+verify)
//   WriteToDisk(path, password)
//   LoadFromDisk(path, password)
//   Sign(data)
//   [export to openssl for generating x509]
//   CreateSelfSignedX509
//   CreateCASignedX509
//   [copy]
// Verifier:
//   Serialize()
//   Deserialize()
//   Verify(data, sig)
//   [copy]
//   GetPrincipalName()
// Deriver (e.g. HKDF):
//   Generate(type=HMAC, purpose=derive)
//   WriteToDisk(password)
//   Derive(n)
//   [copy]
// Crypter:
//   Generate(type=AES, purpose=encrypt+decrypt)
//   WriteToDisk(password)
//   Encrypt()
//   Decrypt()
//   [copy]

namespace tao {
using std::string;

/// A smart pointer to an OpenSSL X509 structure.
typedef scoped_ptr_malloc<X509, CallUnlessNull<X509, X509_free>> ScopedX509;

/// A smart pointer to an OpenSSL EVP_PKEY object.
typedef scoped_ptr_malloc<EVP_PKEY, CallUnlessNull<EVP_PKEY, EVP_PKEY_free>>
    ScopedEvpPkey;

/// A smart pointer to an OpenSSL EC_KEY object.
typedef scoped_ptr_malloc<EC_KEY, CallUnlessNull<EC_KEY, EC_KEY_free>>
    ScopedECKey;

/// A smart pointer to an OpenSSL RSA object.
typedef scoped_ptr_malloc<RSA, CallUnlessNull<RSA, RSA_free>> ScopedRsa;

/// A smart pointer to an OpenSSL BIO object.
typedef scoped_ptr_malloc<BIO, CallUnlessNull<BIO, BIO_free_all>> ScopedBio;

/// Load a clear-text ECDSA verifier key.
/// @param path The location of the key on disk.
/// @param[in,out] key A scoped Verifier to fill with the key.
/// TODO(kwalsh) Eventually, this function should be removed.
bool LoadVerifierKey(const string &path, scoped_ptr<keyczar::Verifier> *key);

/// Load a password-protected ECDSA signing private key.
/// @param path path The location of the key on disk.
/// @param password The password used to encrypt the key on disk.
/// TODO(kwalsh) Eventually, this function should be removed.
bool LoadSigningKey(const string &path, const string &password,
{'fraction_non_alphanumeric': 0.11549497847919656, 'fraction_numerical': 0.01093974175035868, 'mean_word_length': 3.9310344827586206, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2679968', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1823, 'n_words': 607}