@@ -3159,6 +3159,59 @@ const Cipher Cipher::FromCtx(const CipherCtxPointer& ctx) {
31593159 return Cipher (EVP_CIPHER_CTX_cipher (ctx.get ()));
31603160}
31613161
3162+ const Cipher Cipher::EMPTY = Cipher ();
3163+ const Cipher Cipher::AES_128_CBC = Cipher::FromNid (NID_aes_128_cbc);
3164+ const Cipher Cipher::AES_192_CBC = Cipher::FromNid (NID_aes_192_cbc);
3165+ const Cipher Cipher::AES_256_CBC = Cipher::FromNid (NID_aes_256_cbc);
3166+ const Cipher Cipher::AES_128_CTR = Cipher::FromNid (NID_aes_128_ctr);
3167+ const Cipher Cipher::AES_192_CTR = Cipher::FromNid (NID_aes_192_ctr);
3168+ const Cipher Cipher::AES_256_CTR = Cipher::FromNid (NID_aes_256_ctr);
3169+ const Cipher Cipher::AES_128_GCM = Cipher::FromNid (NID_aes_128_gcm);
3170+ const Cipher Cipher::AES_192_GCM = Cipher::FromNid (NID_aes_192_gcm);
3171+ const Cipher Cipher::AES_256_GCM = Cipher::FromNid (NID_aes_256_gcm);
3172+ const Cipher Cipher::AES_128_KW = Cipher::FromNid (NID_id_aes128_wrap);
3173+ const Cipher Cipher::AES_192_KW = Cipher::FromNid (NID_id_aes192_wrap);
3174+ const Cipher Cipher::AES_256_KW = Cipher::FromNid (NID_id_aes256_wrap);
3175+ const Cipher Cipher::AES_128_OCB = Cipher::FromNid (NID_aes_128_ocb);
3176+ const Cipher Cipher::AES_192_OCB = Cipher::FromNid (NID_aes_192_ocb);
3177+ const Cipher Cipher::AES_256_OCB = Cipher::FromNid (NID_aes_256_ocb);
3178+ const Cipher Cipher::CHACHA20_POLY1305 = Cipher::FromNid (NID_chacha20_poly1305);
3179+
3180+ bool Cipher::isGcmMode () const {
3181+ if (!cipher_) return false ;
3182+ return getMode () == EVP_CIPH_GCM_MODE;
3183+ }
3184+
3185+ bool Cipher::isWrapMode () const {
3186+ if (!cipher_) return false ;
3187+ return getMode () == EVP_CIPH_WRAP_MODE;
3188+ }
3189+
3190+ bool Cipher::isCtrMode () const {
3191+ if (!cipher_) return false ;
3192+ return getMode () == EVP_CIPH_CTR_MODE;
3193+ }
3194+
3195+ bool Cipher::isCcmMode () const {
3196+ if (!cipher_) return false ;
3197+ return getMode () == EVP_CIPH_CCM_MODE;
3198+ }
3199+
3200+ bool Cipher::isOcbMode () const {
3201+ if (!cipher_) return false ;
3202+ return getMode () == EVP_CIPH_OCB_MODE;
3203+ }
3204+
3205+ bool Cipher::isStreamMode () const {
3206+ if (!cipher_) return false ;
3207+ return getMode () == EVP_CIPH_STREAM_CIPHER;
3208+ }
3209+
3210+ bool Cipher::isChaCha20Poly1305 () const {
3211+ if (!cipher_) return false ;
3212+ return getNid () == NID_chacha20_poly1305;
3213+ }
3214+
31623215int Cipher::getMode () const {
31633216 if (!cipher_) return 0 ;
31643217 return EVP_CIPHER_mode (cipher_);
@@ -3311,6 +3364,31 @@ int CipherCtxPointer::getMode() const {
33113364 return EVP_CIPHER_CTX_mode (ctx_.get ());
33123365}
33133366
3367+ bool CipherCtxPointer::isGcmMode () const {
3368+ if (!ctx_) return false ;
3369+ return getMode () == EVP_CIPH_GCM_MODE;
3370+ }
3371+
3372+ bool CipherCtxPointer::isOcbMode () const {
3373+ if (!ctx_) return false ;
3374+ return getMode () == EVP_CIPH_OCB_MODE;
3375+ }
3376+
3377+ bool CipherCtxPointer::isCcmMode () const {
3378+ if (!ctx_) return false ;
3379+ return getMode () == EVP_CIPH_CCM_MODE;
3380+ }
3381+
3382+ bool CipherCtxPointer::isWrapMode () const {
3383+ if (!ctx_) return false ;
3384+ return getMode () == EVP_CIPH_WRAP_MODE;
3385+ }
3386+
3387+ bool CipherCtxPointer::isChaCha20Poly1305 () const {
3388+ if (!ctx_) return false ;
3389+ return getNid () == NID_chacha20_poly1305;
3390+ }
3391+
33143392int CipherCtxPointer::getNid () const {
33153393 if (!ctx_) return 0 ;
33163394 return EVP_CIPHER_CTX_nid (ctx_.get ());
0 commit comments