@@ -514,6 +514,79 @@ class Rsa final {
514514 OSSL3_CONST RSA* rsa_;
515515};
516516
517+ class BignumPointer final {
518+ public:
519+ BignumPointer () = default ;
520+ explicit BignumPointer (BIGNUM* bignum);
521+ explicit BignumPointer (const unsigned char * data, size_t len);
522+ BignumPointer (BignumPointer&& other) noexcept ;
523+ BignumPointer& operator =(BignumPointer&& other) noexcept ;
524+ NCRYPTO_DISALLOW_COPY (BignumPointer)
525+ ~BignumPointer ();
526+
527+ int operator <=>(const BignumPointer& other) const noexcept ;
528+ int operator <=>(const BIGNUM* other) const noexcept ;
529+ inline operator bool () const { return bn_ != nullptr ; }
530+ inline BIGNUM* get () const noexcept { return bn_.get (); }
531+ void reset (BIGNUM* bn = nullptr );
532+ void reset (const unsigned char * data, size_t len);
533+ BIGNUM* release ();
534+
535+ bool isZero () const ;
536+ bool isOne () const ;
537+
538+ bool setWord (unsigned long w); // NOLINT(runtime/int)
539+ unsigned long getWord () const ; // NOLINT(runtime/int)
540+
541+ size_t byteLength () const ;
542+ size_t bitLength () const ;
543+
544+ DataPointer toHex () const ;
545+ DataPointer encode () const ;
546+ DataPointer encodePadded (size_t size) const ;
547+ size_t encodeInto (unsigned char * out) const ;
548+ size_t encodePaddedInto (unsigned char * out, size_t size) const ;
549+
550+ using PrimeCheckCallback = std::function<bool (int , int )>;
551+ int isPrime (int checks,
552+ PrimeCheckCallback cb = defaultPrimeCheckCallback) const ;
553+ struct PrimeConfig {
554+ int bits;
555+ bool safe = false ;
556+ const BignumPointer& add;
557+ const BignumPointer& rem;
558+ };
559+
560+ static BignumPointer NewPrime (
561+ const PrimeConfig& params,
562+ PrimeCheckCallback cb = defaultPrimeCheckCallback);
563+
564+ bool generate (const PrimeConfig& params,
565+ PrimeCheckCallback cb = defaultPrimeCheckCallback) const ;
566+
567+ static BignumPointer New ();
568+ static BignumPointer NewSecure ();
569+ static BignumPointer NewSub (const BignumPointer& a, const BignumPointer& b);
570+ static BignumPointer NewLShift (size_t length);
571+
572+ static DataPointer Encode (const BIGNUM* bn);
573+ static DataPointer EncodePadded (const BIGNUM* bn, size_t size);
574+ static size_t EncodePaddedInto (const BIGNUM* bn,
575+ unsigned char * out,
576+ size_t size);
577+ static int GetBitCount (const BIGNUM* bn);
578+ static int GetByteCount (const BIGNUM* bn);
579+ static unsigned long GetWord (const BIGNUM* bn); // NOLINT(runtime/int)
580+ static const BIGNUM* One ();
581+
582+ BignumPointer clone ();
583+
584+ private:
585+ DeleteFnPtr<BIGNUM, BN_clear_free> bn_;
586+
587+ static bool defaultPrimeCheckCallback (int , int ) { return 1 ; }
588+ };
589+
517590class Ec final {
518591 public:
519592 Ec ();
@@ -522,6 +595,10 @@ class Ec final {
522595
523596 const EC_GROUP* getGroup () const ;
524597 int getCurve () const ;
598+ uint32_t getDegree () const ;
599+ std::string getCurveName () const ;
600+ const EC_POINT* getPublicKey () const ;
601+ const BIGNUM* getPrivateKey () const ;
525602
526603 inline operator bool () const { return ec_ != nullptr ; }
527604 inline operator OSSL3_CONST EC_KEY*() const { return ec_; }
@@ -531,8 +608,16 @@ class Ec final {
531608 using GetCurveCallback = std::function<bool (const char *)>;
532609 static bool GetCurves (GetCurveCallback callback);
533610
611+ inline const BignumPointer& getX () const { return x_; }
612+ inline const BignumPointer& getY () const { return y_; }
613+ inline const BignumPointer& getD () const { return d_; }
614+
534615 private:
535616 OSSL3_CONST EC_KEY* ec_ = nullptr ;
617+ // Affine coordinates for the EC_KEY.
618+ BignumPointer x_;
619+ BignumPointer y_;
620+ BignumPointer d_;
536621};
537622
538623// A managed pointer to a buffer of data. When destroyed the underlying
@@ -663,79 +748,6 @@ class BIOPointer final {
663748 mutable DeleteFnPtr<BIO, BIO_free_all> bio_;
664749};
665750
666- class BignumPointer final {
667- public:
668- BignumPointer () = default ;
669- explicit BignumPointer (BIGNUM* bignum);
670- explicit BignumPointer (const unsigned char * data, size_t len);
671- BignumPointer (BignumPointer&& other) noexcept ;
672- BignumPointer& operator =(BignumPointer&& other) noexcept ;
673- NCRYPTO_DISALLOW_COPY (BignumPointer)
674- ~BignumPointer ();
675-
676- int operator <=>(const BignumPointer& other) const noexcept ;
677- int operator <=>(const BIGNUM* other) const noexcept ;
678- inline operator bool () const { return bn_ != nullptr ; }
679- inline BIGNUM* get () const noexcept { return bn_.get (); }
680- void reset (BIGNUM* bn = nullptr );
681- void reset (const unsigned char * data, size_t len);
682- BIGNUM* release ();
683-
684- bool isZero () const ;
685- bool isOne () const ;
686-
687- bool setWord (unsigned long w); // NOLINT(runtime/int)
688- unsigned long getWord () const ; // NOLINT(runtime/int)
689-
690- size_t byteLength () const ;
691- size_t bitLength () const ;
692-
693- DataPointer toHex () const ;
694- DataPointer encode () const ;
695- DataPointer encodePadded (size_t size) const ;
696- size_t encodeInto (unsigned char * out) const ;
697- size_t encodePaddedInto (unsigned char * out, size_t size) const ;
698-
699- using PrimeCheckCallback = std::function<bool (int , int )>;
700- int isPrime (int checks,
701- PrimeCheckCallback cb = defaultPrimeCheckCallback) const ;
702- struct PrimeConfig {
703- int bits;
704- bool safe = false ;
705- const BignumPointer& add;
706- const BignumPointer& rem;
707- };
708-
709- static BignumPointer NewPrime (
710- const PrimeConfig& params,
711- PrimeCheckCallback cb = defaultPrimeCheckCallback);
712-
713- bool generate (const PrimeConfig& params,
714- PrimeCheckCallback cb = defaultPrimeCheckCallback) const ;
715-
716- static BignumPointer New ();
717- static BignumPointer NewSecure ();
718- static BignumPointer NewSub (const BignumPointer& a, const BignumPointer& b);
719- static BignumPointer NewLShift (size_t length);
720-
721- static DataPointer Encode (const BIGNUM* bn);
722- static DataPointer EncodePadded (const BIGNUM* bn, size_t size);
723- static size_t EncodePaddedInto (const BIGNUM* bn,
724- unsigned char * out,
725- size_t size);
726- static int GetBitCount (const BIGNUM* bn);
727- static int GetByteCount (const BIGNUM* bn);
728- static unsigned long GetWord (const BIGNUM* bn); // NOLINT(runtime/int)
729- static const BIGNUM* One ();
730-
731- BignumPointer clone ();
732-
733- private:
734- DeleteFnPtr<BIGNUM, BN_clear_free> bn_;
735-
736- static bool defaultPrimeCheckCallback (int , int ) { return 1 ; }
737- };
738-
739751class CipherCtxPointer final {
740752 public:
741753 static CipherCtxPointer New ();
@@ -977,12 +989,15 @@ class EVPKeyPointer final {
977989 int getDefaultSignPadding () const ;
978990 operator Rsa () const ;
979991 operator Dsa () const ;
992+ operator Ec () const ;
980993
981994 bool isRsaVariant () const ;
982995 bool isOneShotVariant () const ;
983996 bool isSigVariant () const ;
984997 bool validateDsaParameters () const ;
985998
999+ EVPKeyPointer clone () const ;
1000+
9861001 private:
9871002 DeleteFnPtr<EVP_PKEY, EVP_PKEY_free> pkey_;
9881003};
@@ -1617,6 +1632,10 @@ BIOPointer ExportPublicKey(const char* input, size_t length);
16171632// The caller takes ownership of the returned Buffer<char>
16181633Buffer<char > ExportChallenge (const char * input, size_t length);
16191634
1635+ bool VerifySpkac (const Buffer<const char >& buf);
1636+ BIOPointer ExportPublicKey (const Buffer<const char >& buf);
1637+ DataPointer ExportChallenge (const Buffer<const char >& buf);
1638+
16201639// ============================================================================
16211640// KDF
16221641
@@ -1632,6 +1651,13 @@ bool extractP1363(const Buffer<const unsigned char>& buf,
16321651 unsigned char * dest,
16331652 size_t n);
16341653
1654+ bool hkdfInfo (const Digest& md,
1655+ const Buffer<const unsigned char >& key,
1656+ const Buffer<const unsigned char >& info,
1657+ const Buffer<const unsigned char >& salt,
1658+ size_t length,
1659+ Buffer<unsigned char >* out);
1660+
16351661DataPointer hkdf (const Digest& md,
16361662 const Buffer<const unsigned char >& key,
16371663 const Buffer<const unsigned char >& info,
@@ -1640,6 +1666,15 @@ DataPointer hkdf(const Digest& md,
16401666
16411667bool checkScryptParams (uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem);
16421668
1669+ bool scryptInto (const Buffer<const char >& pass,
1670+ const Buffer<const unsigned char >& salt,
1671+ uint64_t N,
1672+ uint64_t r,
1673+ uint64_t p,
1674+ uint64_t maxmem,
1675+ size_t length,
1676+ Buffer<unsigned char >* out);
1677+
16431678DataPointer scrypt (const Buffer<const char >& pass,
16441679 const Buffer<const unsigned char >& salt,
16451680 uint64_t N,
@@ -1648,6 +1683,13 @@ DataPointer scrypt(const Buffer<const char>& pass,
16481683 uint64_t maxmem,
16491684 size_t length);
16501685
1686+ bool pbkdf2Into (const Digest& md,
1687+ const Buffer<const char >& pass,
1688+ const Buffer<const unsigned char >& salt,
1689+ uint32_t iterations,
1690+ size_t length,
1691+ Buffer<unsigned char >* out);
1692+
16511693DataPointer pbkdf2 (const Digest& md,
16521694 const Buffer<const char >& pass,
16531695 const Buffer<const unsigned char >& salt,
0 commit comments