61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
/*
|
|
PIP - Platform Independent Primitives
|
|
Digest algorithms
|
|
Ivan Pelipenko peri4ko@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program 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 Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "pidigest.h"
|
|
|
|
#include "pidigest_md2_p.h"
|
|
#include "pidigest_md4_p.h"
|
|
#include "pidigest_md5_p.h"
|
|
#include "pidigest_sha1_p.h"
|
|
#include "pidigest_sha2_p.h"
|
|
|
|
|
|
int PIDigest::length(Type type) {
|
|
switch (type) {
|
|
case Type::MD2: return 16;
|
|
case Type::MD4: return 16;
|
|
case Type::MD5: return 16;
|
|
case Type::SHA1: return 20;
|
|
case Type::SHA2_224: return 28;
|
|
case Type::SHA2_256: return 32;
|
|
case Type::SHA2_384: return 48;
|
|
case Type::SHA2_512: return 64;
|
|
case Type::SHA2_512_224: return 28;
|
|
case Type::SHA2_512_256: return 32;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
PIByteArray PIDigest::calculate(const PIByteArray & msg, Type type) {
|
|
switch (type) {
|
|
case Type::MD2: return MD2::md2(msg);
|
|
case Type::MD4: return MD4::md4(msg);
|
|
case Type::MD5: return MD5::md5(msg);
|
|
case Type::SHA1: return SHA1::sha1(msg);
|
|
case Type::SHA2_224: return SHA2::sha2xx(msg, SHA2::initial_224, 28);
|
|
case Type::SHA2_256: return SHA2::sha2xx(msg, SHA2::initial_256, 32);
|
|
case Type::SHA2_384: return SHA2::sha5xx(msg, SHA2::initial_384, 48);
|
|
case Type::SHA2_512: return SHA2::sha5xx(msg, SHA2::initial_512, 64);
|
|
case Type::SHA2_512_224: return SHA2::sha5xx(msg, SHA2::initial_512_224, 28);
|
|
case Type::SHA2_512_256: return SHA2::sha5xx(msg, SHA2::initial_512_256, 32);
|
|
}
|
|
return {};
|
|
}
|