#ifndef CONTENT_CHILD_WEBCRYPTO_PLATFORM_CRYPTO_H_
#define CONTENT_CHILD_WEBCRYPTO_PLATFORM_CRYPTO_H_
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/WebKit/public/platform/WebArrayBuffer.h"
#include "third_party/WebKit/public/platform/WebCrypto.h"
#include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
namespace content {
enum EncryptOrDecrypt { ENCRYPT, DECRYPT };
namespace webcrypto {
class CryptoData;
class Status;
namespace platform {
class SymKey;
class PublicKey;
class PrivateKey;
class Key : public blink::WebCryptoKeyHandle {
public:
virtual SymKey* AsSymKey() = 0;
virtual PublicKey* AsPublicKey() = 0;
virtual PrivateKey* AsPrivateKey() = 0;
};
void Init();
Status EncryptDecryptAesCbc(EncryptOrDecrypt mode,
SymKey* key,
const CryptoData& data,
const CryptoData& iv,
blink::WebArrayBuffer* buffer);
Status EncryptDecryptAesGcm(EncryptOrDecrypt mode,
SymKey* key,
const CryptoData& data,
const CryptoData& iv,
const CryptoData& additional_data,
unsigned int tag_length_bits,
blink::WebArrayBuffer* buffer);
Status EncryptRsaEsPkcs1v1_5(PublicKey* key,
const CryptoData& data,
blink::WebArrayBuffer* buffer);
Status DecryptRsaEsPkcs1v1_5(PrivateKey* key,
const CryptoData& data,
blink::WebArrayBuffer* buffer);
Status SignHmac(SymKey* key,
const blink::WebCryptoAlgorithm& hash,
const CryptoData& data,
blink::WebArrayBuffer* buffer);
Status DigestSha(blink::WebCryptoAlgorithmId algorithm,
const CryptoData& data,
blink::WebArrayBuffer* buffer);
scoped_ptr<blink::WebCryptoDigestor> CreateDigestor(
blink::WebCryptoAlgorithmId algorithm);
Status SignRsaSsaPkcs1v1_5(PrivateKey* key,
const blink::WebCryptoAlgorithm& hash,
const CryptoData& data,
blink::WebArrayBuffer* buffer);
Status VerifyRsaSsaPkcs1v1_5(PublicKey* key,
const blink::WebCryptoAlgorithm& hash,
const CryptoData& signature,
const CryptoData& data,
bool* signature_match);
Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
unsigned keylen_bytes,
blink::WebCryptoKey* key);
Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
unsigned int modulus_length_bits,
const CryptoData& public_exponent,
const blink::WebCryptoAlgorithm& hash,
blink::WebCryptoKey* public_key,
blink::WebCryptoKey* private_key);
Status ImportKeyRaw(const blink::WebCryptoAlgorithm& algorithm,
const CryptoData& key_data,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
blink::WebCryptoKey* key);
Status ImportRsaPublicKey(const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
const CryptoData& modulus_data,
const CryptoData& exponent_data,
blink::WebCryptoKey* key);
Status ImportKeySpki(const blink::WebCryptoAlgorithm& algorithm,
const CryptoData& key_data,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
blink::WebCryptoKey* key);
Status ImportKeyPkcs8(const blink::WebCryptoAlgorithm& algorithm,
const CryptoData& key_data,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
blink::WebCryptoKey* key);
Status ExportKeyRaw(SymKey* key, blink::WebArrayBuffer* buffer);
Status ExportKeySpki(PublicKey* key, blink::WebArrayBuffer* buffer);
Status ExportRsaPublicKey(PublicKey* key,
std::vector<uint8>* modulus,
std::vector<uint8>* public_exponent);
Status ExportKeyPkcs8(PrivateKey* key,
const blink::WebCryptoKeyAlgorithm& key_algorithm,
blink::WebArrayBuffer* buffer);
Status WrapSymKeyAesKw(SymKey* wrapping_key,
SymKey* key,
blink::WebArrayBuffer* buffer);
Status UnwrapSymKeyAesKw(const CryptoData& wrapped_key_data,
SymKey* wrapping_key,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
blink::WebCryptoKey* key);
Status DecryptAesKw(SymKey* key,
const CryptoData& data,
blink::WebArrayBuffer* buffer);
Status WrapSymKeyRsaEs(PublicKey* wrapping_key,
SymKey* key,
blink::WebArrayBuffer* buffer);
Status UnwrapSymKeyRsaEs(const CryptoData& wrapped_key_data,
PrivateKey* wrapping_key,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usage_mask,
blink::WebCryptoKey* key);
}
}
}
#endif