⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crypto_wrapper.cpp

📁 这是linux下运行的mysql软件包,可用于linux 下安装 php + mysql + apach 的网络配置
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* crypto_wrapper.cpp   * * Copyright (C) 2003 Sawtooth Consulting Ltd. * * This file is part of yaSSL. * * yaSSL is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * yaSSL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA *//*  The crypto wrapper source implements the policies for the cipher *  components used by SSL. * *  The implementation relies on a specfic library, taoCrypt. */#if !defined(USE_CRYPTOPP_LIB)#include "runtime.hpp"#include "crypto_wrapper.hpp"#include "cert_wrapper.hpp"#include "md5.hpp"#include "sha.hpp"#include "ripemd.hpp"#include "hmac.hpp"#include "modes.hpp"#include "des.hpp"#include "arc4.hpp"#include "aes.hpp"#include "rsa.hpp"#include "dsa.hpp"#include "dh.hpp"#include "random.hpp"#include "file.hpp"#include "coding.hpp"namespace yaSSL {// MD5 Implementationstruct MD5::MD5Impl {    TaoCrypt::MD5 md5_;    MD5Impl() {}    explicit MD5Impl(const TaoCrypt::MD5& md5) : md5_(md5) {}};MD5::MD5() : pimpl_(new (ys) MD5Impl) {}MD5::~MD5() { ysDelete(pimpl_); }MD5::MD5(const MD5& that) : Digest(), pimpl_(new (ys)                                              MD5Impl(that.pimpl_->md5_)) {}MD5& MD5::operator=(const MD5& that){    pimpl_->md5_ = that.pimpl_->md5_;    return *this;}uint MD5::get_digestSize() const{    return MD5_LEN;}uint MD5::get_padSize() const{    return PAD_MD5;}// Fill out with MD5 digest from in that is sz bytes, out must be >= digest szvoid MD5::get_digest(byte* out, const byte* in, unsigned int sz){    pimpl_->md5_.Update(in, sz);    pimpl_->md5_.Final(out);}// Fill out with MD5 digest from previous updatesvoid MD5::get_digest(byte* out){    pimpl_->md5_.Final(out);}// Update the current digestvoid MD5::update(const byte* in, unsigned int sz){    pimpl_->md5_.Update(in, sz);}// SHA Implementationstruct SHA::SHAImpl {    TaoCrypt::SHA sha_;    SHAImpl() {}    explicit SHAImpl(const TaoCrypt::SHA& sha) : sha_(sha) {}};SHA::SHA() : pimpl_(new (ys) SHAImpl) {}SHA::~SHA() { ysDelete(pimpl_); }SHA::SHA(const SHA& that) : Digest(), pimpl_(new (ys) SHAImpl(that.pimpl_->sha_)) {}SHA& SHA::operator=(const SHA& that){    pimpl_->sha_ = that.pimpl_->sha_;    return *this;}uint SHA::get_digestSize() const{    return SHA_LEN;}uint SHA::get_padSize() const{    return PAD_SHA;}// Fill out with SHA digest from in that is sz bytes, out must be >= digest szvoid SHA::get_digest(byte* out, const byte* in, unsigned int sz){    pimpl_->sha_.Update(in, sz);    pimpl_->sha_.Final(out);}// Fill out with SHA digest from previous updatesvoid SHA::get_digest(byte* out){    pimpl_->sha_.Final(out);}// Update the current digestvoid SHA::update(const byte* in, unsigned int sz){    pimpl_->sha_.Update(in, sz);}// RMD-160 Implementationstruct RMD::RMDImpl {    TaoCrypt::RIPEMD160 rmd_;    RMDImpl() {}    explicit RMDImpl(const TaoCrypt::RIPEMD160& rmd) : rmd_(rmd) {}};RMD::RMD() : pimpl_(new (ys) RMDImpl) {}RMD::~RMD() { ysDelete(pimpl_); }RMD::RMD(const RMD& that) : Digest(), pimpl_(new (ys) RMDImpl(that.pimpl_->rmd_)) {}RMD& RMD::operator=(const RMD& that){    pimpl_->rmd_ = that.pimpl_->rmd_;    return *this;}uint RMD::get_digestSize() const{    return RMD_LEN;}uint RMD::get_padSize() const{    return PAD_RMD;}// Fill out with RMD digest from in that is sz bytes, out must be >= digest szvoid RMD::get_digest(byte* out, const byte* in, unsigned int sz){    pimpl_->rmd_.Update(in, sz);    pimpl_->rmd_.Final(out);}// Fill out with RMD digest from previous updatesvoid RMD::get_digest(byte* out){    pimpl_->rmd_.Final(out);}// Update the current digestvoid RMD::update(const byte* in, unsigned int sz){    pimpl_->rmd_.Update(in, sz);}// HMAC_MD5 Implementationstruct HMAC_MD5::HMAC_MD5Impl {    TaoCrypt::HMAC<TaoCrypt::MD5> mac_;    HMAC_MD5Impl() {}};HMAC_MD5::HMAC_MD5(const byte* secret, unsigned int len)     : pimpl_(new (ys) HMAC_MD5Impl) {    pimpl_->mac_.SetKey(secret, len);}HMAC_MD5::~HMAC_MD5() { ysDelete(pimpl_); }uint HMAC_MD5::get_digestSize() const{    return MD5_LEN;}uint HMAC_MD5::get_padSize() const{    return PAD_MD5;}// Fill out with MD5 digest from in that is sz bytes, out must be >= digest szvoid HMAC_MD5::get_digest(byte* out, const byte* in, unsigned int sz){    pimpl_->mac_.Update(in, sz);    pimpl_->mac_.Final(out);}// Fill out with MD5 digest from previous updatesvoid HMAC_MD5::get_digest(byte* out){    pimpl_->mac_.Final(out);}// Update the current digestvoid HMAC_MD5::update(const byte* in, unsigned int sz){    pimpl_->mac_.Update(in, sz);}// HMAC_SHA Implementationstruct HMAC_SHA::HMAC_SHAImpl {    TaoCrypt::HMAC<TaoCrypt::SHA> mac_;    HMAC_SHAImpl() {}};HMAC_SHA::HMAC_SHA(const byte* secret, unsigned int len)     : pimpl_(new (ys) HMAC_SHAImpl) {    pimpl_->mac_.SetKey(secret, len);}HMAC_SHA::~HMAC_SHA() { ysDelete(pimpl_); }uint HMAC_SHA::get_digestSize() const{    return SHA_LEN;}uint HMAC_SHA::get_padSize() const{    return PAD_SHA;}// Fill out with SHA digest from in that is sz bytes, out must be >= digest szvoid HMAC_SHA::get_digest(byte* out, const byte* in, unsigned int sz){    pimpl_->mac_.Update(in, sz);    pimpl_->mac_.Final(out);}// Fill out with SHA digest from previous updatesvoid HMAC_SHA::get_digest(byte* out){    pimpl_->mac_.Final(out);}// Update the current digestvoid HMAC_SHA::update(const byte* in, unsigned int sz){    pimpl_->mac_.Update(in, sz);}// HMAC_RMD Implementationstruct HMAC_RMD::HMAC_RMDImpl {    TaoCrypt::HMAC<TaoCrypt::RIPEMD160> mac_;    HMAC_RMDImpl() {}};HMAC_RMD::HMAC_RMD(const byte* secret, unsigned int len)     : pimpl_(new (ys) HMAC_RMDImpl) {    pimpl_->mac_.SetKey(secret, len);}HMAC_RMD::~HMAC_RMD() { ysDelete(pimpl_); }uint HMAC_RMD::get_digestSize() const{    return RMD_LEN;}uint HMAC_RMD::get_padSize() const{    return PAD_RMD;}// Fill out with RMD digest from in that is sz bytes, out must be >= digest szvoid HMAC_RMD::get_digest(byte* out, const byte* in, unsigned int sz){    pimpl_->mac_.Update(in, sz);    pimpl_->mac_.Final(out);}// Fill out with RMD digest from previous updatesvoid HMAC_RMD::get_digest(byte* out){    pimpl_->mac_.Final(out);}// Update the current digestvoid HMAC_RMD::update(const byte* in, unsigned int sz){    pimpl_->mac_.Update(in, sz);}struct DES::DESImpl {    TaoCrypt::DES_CBC_Encryption encryption;    TaoCrypt::DES_CBC_Decryption decryption;};DES::DES() : pimpl_(new (ys) DESImpl) {}DES::~DES() { ysDelete(pimpl_); }void DES::set_encryptKey(const byte* k, const byte* iv){    pimpl_->encryption.SetKey(k, DES_KEY_SZ, iv);}void DES::set_decryptKey(const byte* k, const byte* iv){    pimpl_->decryption.SetKey(k, DES_KEY_SZ, iv);}// DES encrypt plain of length sz into ciphervoid DES::encrypt(byte* cipher, const byte* plain, unsigned int sz){    pimpl_->encryption.Process(cipher, plain, sz);}// DES decrypt cipher of length sz into plainvoid DES::decrypt(byte* plain, const byte* cipher, unsigned int sz){    pimpl_->decryption.Process(plain, cipher, sz);}struct DES_EDE::DES_EDEImpl {    TaoCrypt::DES_EDE3_CBC_Encryption encryption;    TaoCrypt::DES_EDE3_CBC_Decryption decryption;};DES_EDE::DES_EDE() : pimpl_(new (ys) DES_EDEImpl) {}DES_EDE::~DES_EDE() { ysDelete(pimpl_); }void DES_EDE::set_encryptKey(const byte* k, const byte* iv){    pimpl_->encryption.SetKey(k, DES_EDE_KEY_SZ, iv);}void DES_EDE::set_decryptKey(const byte* k, const byte* iv){    pimpl_->decryption.SetKey(k, DES_EDE_KEY_SZ, iv);}// 3DES encrypt plain of length sz into ciphervoid DES_EDE::encrypt(byte* cipher, const byte* plain, unsigned int sz){    pimpl_->encryption.Process(cipher, plain, sz);}// 3DES decrypt cipher of length sz into plainvoid DES_EDE::decrypt(byte* plain, const byte* cipher, unsigned int sz){    pimpl_->decryption.Process(plain, cipher, sz);}// Implementation of alledged RC4struct RC4::RC4Impl {    TaoCrypt::ARC4::Encryption encryption;    TaoCrypt::ARC4::Decryption decryption;};RC4::RC4() : pimpl_(new (ys) RC4Impl) {}RC4::~RC4() { ysDelete(pimpl_); }void RC4::set_encryptKey(const byte* k, const byte*){    pimpl_->encryption.SetKey(k, RC4_KEY_SZ);}void RC4::set_decryptKey(const byte* k, const byte*){    pimpl_->decryption.SetKey(k, RC4_KEY_SZ);}// RC4 encrypt plain of length sz into ciphervoid RC4::encrypt(byte* cipher, const byte* plain, unsigned int sz){    pimpl_->encryption.Process(cipher, plain, sz);}// RC4 decrypt cipher of length sz into plainvoid RC4::decrypt(byte* plain, const byte* cipher, unsigned int sz){    pimpl_->decryption.Process(plain, cipher, sz);}// Implementation of AESstruct AES::AESImpl {    TaoCrypt::AES_CBC_Encryption encryption;    TaoCrypt::AES_CBC_Decryption decryption;    unsigned int keySz_;    AESImpl(unsigned int ks) : keySz_(ks) {}};AES::AES(unsigned int ks) : pimpl_(new (ys) AESImpl(ks)) {}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -