111 lines
2.5 KiB
C++
111 lines
2.5 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: ECC.cpp
|
|
Date: 2021-9-17
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "ECC.hpp"
|
|
#include "ECCGeneric.hpp"
|
|
#include "ECCCurves.hpp"
|
|
#include "PublicECCImpl.hpp"
|
|
#include "PrivateECCImpl.hpp"
|
|
|
|
|
|
namespace Aurora::Crypto::ECC
|
|
{
|
|
|
|
static void ReleasePublicECC(IECCPublic *pub)
|
|
{
|
|
switch (pub->GetType())
|
|
{
|
|
case EECCCurve::eCurveEd25519:
|
|
case EECCCurve::eCurveX25519:
|
|
return;
|
|
default:
|
|
SafeDelete<PublicECCImpl *>(pub);
|
|
return;
|
|
}
|
|
}
|
|
|
|
static void ReleasePrivateECC(IECCPrivate *priv)
|
|
{
|
|
switch (priv->GetType())
|
|
{
|
|
case EECCCurve::eCurveEd25519:
|
|
case EECCCurve::eCurveX25519:
|
|
return;
|
|
default:
|
|
SafeDelete<PrivateECCImpl *>(priv);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
AUKN_SYM IECCPrivate *NewECC(EECCCurve curve)
|
|
{
|
|
switch (curve)
|
|
{
|
|
case EECCCurve::eCurveEd25519:
|
|
case EECCCurve::eCurveX25519:
|
|
// TODO: Curve25519 is special
|
|
return {};
|
|
default:
|
|
return GenerateNewGenericECC(curve).value_or(nullptr);
|
|
}
|
|
}
|
|
|
|
AUKN_SYM IECCPrivate *OpenPrivateECC(const Memory::MemoryViewRead &pk)
|
|
{
|
|
if (auto ret = NewStdECC<PrivateECCImpl>({}/*no curve assertion*/, pk, false))
|
|
{
|
|
return ret;
|
|
}
|
|
|
|
// TODO: Curve25519 is special
|
|
return {};
|
|
}
|
|
|
|
AUKN_SYM IECCPublic *OpenPublicECC(const Memory::MemoryViewRead &pk)
|
|
{
|
|
if (auto ret = NewStdECC<PublicECCImpl>({}/*no curve assertion*/, pk, false))
|
|
{
|
|
return ret;
|
|
}
|
|
|
|
// TODO: Curve25519 is special
|
|
return {};
|
|
}
|
|
|
|
AUKN_SYM IECCPublic *OpenPublicECCFromCert(const Memory::MemoryViewRead &certificate)
|
|
{
|
|
if (auto ret = NewStdECC<PublicECCImpl>({}/*no curve assertion*/, certificate, true))
|
|
{
|
|
return ret;
|
|
}
|
|
|
|
// TODO: Curve25519 is special
|
|
return {};
|
|
}
|
|
|
|
AUKN_SYM void NewECCRelease(IECCPrivate *priv)
|
|
{
|
|
ReleasePrivateECC(priv);
|
|
}
|
|
|
|
AUKN_SYM void OpenPrivateECCRelease(IECCPrivate *priv)
|
|
{
|
|
ReleasePrivateECC(priv);
|
|
}
|
|
|
|
AUKN_SYM void OpenPublicECCRelease(IECCPublic *pub)
|
|
{
|
|
ReleasePublicECC(pub);
|
|
}
|
|
|
|
AUKN_SYM void OpenPublicECCFromCertRelease(IECCPublic *pub)
|
|
{
|
|
ReleasePublicECC(pub);
|
|
}
|
|
} |