Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
424e4ee1
Commit
424e4ee1
authored
May 24, 2005
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/home/dlenev/src/mysql-5.0-bg5860
parents
896786ea
3c50d954
Changes
28
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
283 additions
and
715 deletions
+283
-715
extra/yassl/include/factory.hpp
extra/yassl/include/factory.hpp
+1
-1
extra/yassl/include/yassl_int.hpp
extra/yassl/include/yassl_int.hpp
+1
-1
extra/yassl/include/yassl_types.hpp
extra/yassl/include/yassl_types.hpp
+0
-10
extra/yassl/src/buffer.cpp
extra/yassl/src/buffer.cpp
+6
-6
extra/yassl/src/cert_wrapper.cpp
extra/yassl/src/cert_wrapper.cpp
+12
-12
extra/yassl/src/crypto_wrapper.cpp
extra/yassl/src/crypto_wrapper.cpp
+27
-31
extra/yassl/src/handshake.cpp
extra/yassl/src/handshake.cpp
+15
-15
extra/yassl/src/ssl.cpp
extra/yassl/src/ssl.cpp
+2
-2
extra/yassl/src/yassl_imp.cpp
extra/yassl/src/yassl_imp.cpp
+39
-40
extra/yassl/src/yassl_int.cpp
extra/yassl/src/yassl_int.cpp
+53
-74
extra/yassl/taocrypt/include/aes.hpp
extra/yassl/taocrypt/include/aes.hpp
+3
-2
extra/yassl/taocrypt/include/algebra.hpp
extra/yassl/taocrypt/include/algebra.hpp
+19
-107
extra/yassl/taocrypt/include/block.hpp
extra/yassl/taocrypt/include/block.hpp
+8
-12
extra/yassl/taocrypt/include/des.hpp
extra/yassl/taocrypt/include/des.hpp
+3
-2
extra/yassl/taocrypt/include/error.hpp
extra/yassl/taocrypt/include/error.hpp
+2
-1
extra/yassl/taocrypt/include/hash.hpp
extra/yassl/taocrypt/include/hash.hpp
+1
-1
extra/yassl/taocrypt/include/integer.hpp
extra/yassl/taocrypt/include/integer.hpp
+3
-7
extra/yassl/taocrypt/include/misc.hpp
extra/yassl/taocrypt/include/misc.hpp
+0
-11
extra/yassl/taocrypt/include/modarith.hpp
extra/yassl/taocrypt/include/modarith.hpp
+6
-7
extra/yassl/taocrypt/include/modes.hpp
extra/yassl/taocrypt/include/modes.hpp
+27
-28
extra/yassl/taocrypt/src/algebra.cpp
extra/yassl/taocrypt/src/algebra.cpp
+37
-62
extra/yassl/taocrypt/src/asn.cpp
extra/yassl/taocrypt/src/asn.cpp
+10
-10
extra/yassl/taocrypt/src/dh.cpp
extra/yassl/taocrypt/src/dh.cpp
+0
-1
extra/yassl/taocrypt/src/dsa.cpp
extra/yassl/taocrypt/src/dsa.cpp
+0
-2
extra/yassl/taocrypt/src/integer.cpp
extra/yassl/taocrypt/src/integer.cpp
+8
-235
extra/yassl/taocrypt/src/misc.cpp
extra/yassl/taocrypt/src/misc.cpp
+0
-27
extra/yassl/taocrypt/src/random.cpp
extra/yassl/taocrypt/src/random.cpp
+0
-1
extra/yassl/taocrypt/src/rsa.cpp
extra/yassl/taocrypt/src/rsa.cpp
+0
-7
No files found.
extra/yassl/include/factory.hpp
View file @
424e4ee1
...
...
@@ -67,7 +67,7 @@ public:
init
(
*
this
);
}
// reserv
c
e place in vector before registering, used by init funcion
// reserve place in vector before registering, used by init funcion
void
Reserve
(
size_t
sz
)
{
callbacks_
.
reserve
(
sz
);
...
...
extra/yassl/include/yassl_int.hpp
View file @
424e4ee1
...
...
@@ -31,8 +31,8 @@
#include "yassl_imp.hpp"
#include "crypto_wrapper.hpp"
#include "cert_wrapper.hpp"
#include "lock.hpp"
#include "log.hpp"
#include "lock.hpp"
namespace
yaSSL
{
...
...
extra/yassl/include/yassl_types.hpp
View file @
424e4ee1
...
...
@@ -29,16 +29,6 @@
#include <stddef.h>
namespace
yaSSL
{
// library allocation
struct
new_t
{};
// yaSSL New type
extern
new_t
ys
;
// pass in parameter
}
// namespace yaSSL
void
*
operator
new
(
size_t
,
yaSSL
::
new_t
);
void
*
operator
new
[](
size_t
,
yaSSL
::
new_t
);
namespace
yaSSL
{
...
...
extra/yassl/src/buffer.cpp
View file @
424e4ee1
...
...
@@ -62,13 +62,13 @@ input_buffer::input_buffer()
input_buffer
::
input_buffer
(
uint
s
)
:
size_
(
0
),
current_
(
0
),
buffer_
(
new
(
ys
)
byte
[
s
]),
end_
(
buffer_
+
s
)
:
size_
(
0
),
current_
(
0
),
buffer_
(
new
byte
[
s
]),
end_
(
buffer_
+
s
)
{}
// with assign
input_buffer
::
input_buffer
(
uint
s
,
const
byte
*
t
,
uint
len
)
:
size_
(
0
),
current_
(
0
),
buffer_
(
new
(
ys
)
byte
[
s
]),
end_
(
buffer_
+
s
)
:
size_
(
0
),
current_
(
0
),
buffer_
(
new
byte
[
s
]),
end_
(
buffer_
+
s
)
{
assign
(
t
,
len
);
}
...
...
@@ -84,7 +84,7 @@ input_buffer::~input_buffer()
void
input_buffer
::
allocate
(
uint
s
)
{
assert
(
!
buffer_
);
// find realloc error
buffer_
=
new
(
ys
)
byte
[
s
];
buffer_
=
new
byte
[
s
];
end_
=
buffer_
+
s
;
}
...
...
@@ -198,13 +198,13 @@ output_buffer::output_buffer()
// with allocate
output_buffer
::
output_buffer
(
uint
s
)
:
current_
(
0
),
buffer_
(
new
(
ys
)
byte
[
s
]),
end_
(
buffer_
+
s
)
:
current_
(
0
),
buffer_
(
new
byte
[
s
]),
end_
(
buffer_
+
s
)
{}
// with assign
output_buffer
::
output_buffer
(
uint
s
,
const
byte
*
t
,
uint
len
)
:
current_
(
0
),
buffer_
(
new
(
ys
)
byte
[
s
]),
end_
(
buffer_
+
s
)
:
current_
(
0
),
buffer_
(
new
byte
[
s
]),
end_
(
buffer_
+
s
)
{
write
(
t
,
len
);
}
...
...
@@ -239,7 +239,7 @@ void output_buffer::set_current(uint c)
void
output_buffer
::
allocate
(
uint
s
)
{
assert
(
!
buffer_
);
// find realloc error
buffer_
=
new
(
ys
)
byte
[
s
];
end_
=
buffer_
+
s
;
buffer_
=
new
byte
[
s
];
end_
=
buffer_
+
s
;
}
...
...
extra/yassl/src/cert_wrapper.cpp
View file @
424e4ee1
...
...
@@ -39,7 +39,7 @@
namespace
yaSSL
{
x509
::
x509
(
uint
sz
)
:
length_
(
sz
),
buffer_
(
new
(
ys
)
opaque
[
sz
])
x509
::
x509
(
uint
sz
)
:
length_
(
sz
),
buffer_
(
new
opaque
[
sz
])
{
}
...
...
@@ -51,7 +51,7 @@ x509::~x509()
x509
::
x509
(
const
x509
&
that
)
:
length_
(
that
.
length_
),
buffer_
(
new
(
ys
)
opaque
[
length_
])
buffer_
(
new
opaque
[
length_
])
{
memcpy
(
buffer_
,
that
.
buffer_
,
length_
);
}
...
...
@@ -153,7 +153,7 @@ void CertManager::AddPeerCert(x509* x)
void
CertManager
::
CopySelfCert
(
const
x509
*
x
)
{
if
(
x
)
list_
.
push_back
(
new
(
ys
)
x509
(
*
x
));
list_
.
push_back
(
new
x509
(
*
x
));
}
...
...
@@ -165,7 +165,7 @@ int CertManager::CopyCaCert(const x509* x)
if
(
!
cert
.
GetError
().
What
())
{
const
TaoCrypt
::
PublicKey
&
key
=
cert
.
GetPublicKey
();
signers_
.
push_back
(
new
(
ys
)
TaoCrypt
::
Signer
(
key
.
GetKey
(),
key
.
size
(),
signers_
.
push_back
(
new
TaoCrypt
::
Signer
(
key
.
GetKey
(),
key
.
size
(),
cert
.
GetCommonName
(),
cert
.
GetHash
()));
}
return
cert
.
GetError
().
What
();
...
...
@@ -234,7 +234,7 @@ int CertManager::Validate()
return
err
;
const
TaoCrypt
::
PublicKey
&
key
=
cert
.
GetPublicKey
();
signers_
.
push_back
(
new
(
ys
)
TaoCrypt
::
Signer
(
key
.
GetKey
(),
key
.
size
(),
signers_
.
push_back
(
new
TaoCrypt
::
Signer
(
key
.
GetKey
(),
key
.
size
(),
cert
.
GetCommonName
(),
cert
.
GetHash
()));
--
last
;
--
count
;
...
...
@@ -259,7 +259,7 @@ int CertManager::Validate()
int
iSz
=
cert
.
GetIssuer
()
?
strlen
(
cert
.
GetIssuer
())
+
1
:
0
;
int
sSz
=
cert
.
GetCommonName
()
?
strlen
(
cert
.
GetCommonName
())
+
1
:
0
;
peerX509_
=
new
(
ys
)
X509
(
cert
.
GetIssuer
(),
iSz
,
cert
.
GetCommonName
(),
peerX509_
=
new
X509
(
cert
.
GetIssuer
(),
iSz
,
cert
.
GetCommonName
(),
sSz
);
}
return
0
;
...
...
@@ -273,13 +273,13 @@ int CertManager::SetPrivateKey(const x509& key)
privateKey_
.
assign
(
key
.
get_buffer
(),
key
.
get_length
());
// set key type
if
(
x509
*
cert
509
=
list_
.
front
())
{
TaoCrypt
::
Source
source
(
cert
509
->
get_buffer
(),
cert509
->
get_length
());
TaoCrypt
::
CertDecoder
c
ert
(
source
,
false
);
c
ert
.
DecodeToKey
();
if
(
int
err
=
c
ert
.
GetError
().
What
())
if
(
x509
*
cert
=
list_
.
front
())
{
TaoCrypt
::
Source
source
(
cert
->
get_buffer
(),
cert
->
get_length
());
TaoCrypt
::
CertDecoder
c
d
(
source
,
false
);
c
d
.
DecodeToKey
();
if
(
int
err
=
c
d
.
GetError
().
What
())
return
err
;
if
(
c
ert
.
GetKeyType
()
==
TaoCrypt
::
RSAk
)
if
(
c
d
.
GetKeyType
()
==
TaoCrypt
::
RSAk
)
keyType_
=
rsa_sa_algo
;
else
keyType_
=
dsa_sa_algo
;
...
...
extra/yassl/src/crypto_wrapper.cpp
View file @
424e4ee1
...
...
@@ -58,13 +58,13 @@ struct MD5::MD5Impl {
};
MD5
::
MD5
()
:
pimpl_
(
new
(
ys
)
MD5Impl
)
{}
MD5
::
MD5
()
:
pimpl_
(
new
MD5Impl
)
{}
MD5
::~
MD5
()
{
delete
pimpl_
;
}
MD5
::
MD5
(
const
MD5
&
that
)
:
Digest
(),
pimpl_
(
new
(
ys
)
MD5
::
MD5
(
const
MD5
&
that
)
:
Digest
(),
pimpl_
(
new
MD5Impl
(
that
.
pimpl_
->
md5_
))
{}
...
...
@@ -116,14 +116,13 @@ struct SHA::SHAImpl {
};
SHA
::
SHA
()
:
pimpl_
(
new
(
ys
)
SHAImpl
)
{}
SHA
::
SHA
()
:
pimpl_
(
new
SHAImpl
)
{}
SHA
::~
SHA
()
{
delete
pimpl_
;
}
SHA
::
SHA
(
const
SHA
&
that
)
:
Digest
(),
pimpl_
(
new
(
ys
)
SHAImpl
(
that
.
pimpl_
->
sha_
))
{}
SHA
::
SHA
(
const
SHA
&
that
)
:
Digest
(),
pimpl_
(
new
SHAImpl
(
that
.
pimpl_
->
sha_
))
{}
SHA
&
SHA
::
operator
=
(
const
SHA
&
that
)
{
...
...
@@ -174,14 +173,13 @@ struct RMD::RMDImpl {
};
RMD
::
RMD
()
:
pimpl_
(
new
(
ys
)
RMDImpl
)
{}
RMD
::
RMD
()
:
pimpl_
(
new
RMDImpl
)
{}
RMD
::~
RMD
()
{
delete
pimpl_
;
}
RMD
::
RMD
(
const
RMD
&
that
)
:
Digest
(),
pimpl_
(
new
(
ys
)
RMDImpl
(
that
.
pimpl_
->
rmd_
))
{}
RMD
::
RMD
(
const
RMD
&
that
)
:
Digest
(),
pimpl_
(
new
RMDImpl
(
that
.
pimpl_
->
rmd_
))
{}
RMD
&
RMD
::
operator
=
(
const
RMD
&
that
)
{
...
...
@@ -232,7 +230,7 @@ struct HMAC_MD5::HMAC_MD5Impl {
HMAC_MD5
::
HMAC_MD5
(
const
byte
*
secret
,
unsigned
int
len
)
:
pimpl_
(
new
(
ys
)
HMAC_MD5Impl
)
:
pimpl_
(
new
HMAC_MD5Impl
)
{
pimpl_
->
mac_
.
SetKey
(
secret
,
len
);
}
...
...
@@ -282,7 +280,7 @@ struct HMAC_SHA::HMAC_SHAImpl {
HMAC_SHA
::
HMAC_SHA
(
const
byte
*
secret
,
unsigned
int
len
)
:
pimpl_
(
new
(
ys
)
HMAC_SHAImpl
)
:
pimpl_
(
new
HMAC_SHAImpl
)
{
pimpl_
->
mac_
.
SetKey
(
secret
,
len
);
}
...
...
@@ -333,7 +331,7 @@ struct HMAC_RMD::HMAC_RMDImpl {
HMAC_RMD
::
HMAC_RMD
(
const
byte
*
secret
,
unsigned
int
len
)
:
pimpl_
(
new
(
ys
)
HMAC_RMDImpl
)
:
pimpl_
(
new
HMAC_RMDImpl
)
{
pimpl_
->
mac_
.
SetKey
(
secret
,
len
);
}
...
...
@@ -381,7 +379,7 @@ struct DES::DESImpl {
};
DES
::
DES
()
:
pimpl_
(
new
(
ys
)
DESImpl
)
{}
DES
::
DES
()
:
pimpl_
(
new
DESImpl
)
{}
DES
::~
DES
()
{
delete
pimpl_
;
}
...
...
@@ -417,7 +415,7 @@ struct DES_EDE::DES_EDEImpl {
};
DES_EDE
::
DES_EDE
()
:
pimpl_
(
new
(
ys
)
DES_EDEImpl
)
{}
DES_EDE
::
DES_EDE
()
:
pimpl_
(
new
DES_EDEImpl
)
{}
DES_EDE
::~
DES_EDE
()
{
delete
pimpl_
;
}
...
...
@@ -455,7 +453,7 @@ struct RC4::RC4Impl {
};
RC4
::
RC4
()
:
pimpl_
(
new
(
ys
)
RC4Impl
)
{}
RC4
::
RC4
()
:
pimpl_
(
new
RC4Impl
)
{}
RC4
::~
RC4
()
{
delete
pimpl_
;
}
...
...
@@ -497,7 +495,7 @@ struct AES::AESImpl {
};
AES
::
AES
(
unsigned
int
ks
)
:
pimpl_
(
new
(
ys
)
AESImpl
(
ks
))
{}
AES
::
AES
(
unsigned
int
ks
)
:
pimpl_
(
new
AESImpl
(
ks
))
{}
AES
::~
AES
()
{
delete
pimpl_
;
}
...
...
@@ -538,7 +536,7 @@ struct RandomPool::RandomImpl {
TaoCrypt
::
RandomNumberGenerator
RNG_
;
};
RandomPool
::
RandomPool
()
:
pimpl_
(
new
(
ys
)
RandomImpl
)
{}
RandomPool
::
RandomPool
()
:
pimpl_
(
new
RandomImpl
)
{}
RandomPool
::~
RandomPool
()
{
delete
pimpl_
;
}
...
...
@@ -582,7 +580,7 @@ void DSS::DSSImpl::SetPrivate(const byte* key, unsigned int sz)
// Set public or private key
DSS
::
DSS
(
const
byte
*
key
,
unsigned
int
sz
,
bool
publicKey
)
:
pimpl_
(
new
(
ys
)
DSSImpl
)
:
pimpl_
(
new
DSSImpl
)
{
if
(
publicKey
)
pimpl_
->
SetPublic
(
key
,
sz
);
...
...
@@ -653,7 +651,7 @@ void RSA::RSAImpl::SetPrivate(const byte* key, unsigned int sz)
// Set public or private key
RSA
::
RSA
(
const
byte
*
key
,
unsigned
int
sz
,
bool
publicKey
)
:
pimpl_
(
new
(
ys
)
RSAImpl
)
:
pimpl_
(
new
RSAImpl
)
{
if
(
publicKey
)
pimpl_
->
SetPublic
(
key
,
sz
);
...
...
@@ -725,13 +723,13 @@ struct Integer::IntegerImpl {
explicit
IntegerImpl
(
const
TaoCrypt
::
Integer
&
i
)
:
int_
(
i
)
{}
};
Integer
::
Integer
()
:
pimpl_
(
new
(
ys
)
IntegerImpl
)
{}
Integer
::
Integer
()
:
pimpl_
(
new
IntegerImpl
)
{}
Integer
::~
Integer
()
{
delete
pimpl_
;
}
Integer
::
Integer
(
const
Integer
&
other
)
:
pimpl_
(
new
(
ys
)
Integer
::
Integer
(
const
Integer
&
other
)
:
pimpl_
(
new
IntegerImpl
(
other
.
pimpl_
->
int_
))
{}
...
...
@@ -770,9 +768,9 @@ struct DiffieHellman::DHImpl {
void
AllocKeys
(
unsigned
int
pubSz
,
unsigned
int
privSz
,
unsigned
int
agrSz
)
{
publicKey_
=
new
(
ys
)
byte
[
pubSz
];
privateKey_
=
new
(
ys
)
byte
[
privSz
];
agreedKey_
=
new
(
ys
)
byte
[
agrSz
];
publicKey_
=
new
byte
[
pubSz
];
privateKey_
=
new
byte
[
privSz
];
agreedKey_
=
new
byte
[
agrSz
];
}
};
...
...
@@ -781,7 +779,7 @@ struct DiffieHellman::DHImpl {
/*
// server Side DH, server's view
DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
: pimpl_(new
(ys)
DHImpl(random.pimpl_->RNG_))
: pimpl_(new DHImpl(random.pimpl_->RNG_))
{
using namespace TaoCrypt;
Source source;
...
...
@@ -805,12 +803,12 @@ DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
DiffieHellman
::
DiffieHellman
(
const
byte
*
p
,
unsigned
int
pSz
,
const
byte
*
g
,
unsigned
int
gSz
,
const
byte
*
pub
,
unsigned
int
pubSz
,
const
RandomPool
&
random
)
:
pimpl_
(
new
(
ys
)
DHImpl
(
random
.
pimpl_
->
RNG_
))
:
pimpl_
(
new
DHImpl
(
random
.
pimpl_
->
RNG_
))
{
using
TaoCrypt
::
Integer
;
pimpl_
->
dh_
.
Initialize
(
Integer
(
p
,
pSz
).
Ref
(),
Integer
(
g
,
gSz
).
Ref
());
pimpl_
->
publicKey_
=
new
(
ys
)
opaque
[
pubSz
];
pimpl_
->
publicKey_
=
new
opaque
[
pubSz
];
memcpy
(
pimpl_
->
publicKey_
,
pub
,
pubSz
);
}
...
...
@@ -818,7 +816,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
// Server Side DH, server's view
DiffieHellman
::
DiffieHellman
(
const
Integer
&
p
,
const
Integer
&
g
,
const
RandomPool
&
random
)
:
pimpl_
(
new
(
ys
)
DHImpl
(
random
.
pimpl_
->
RNG_
))
:
pimpl_
(
new
DHImpl
(
random
.
pimpl_
->
RNG_
))
{
using
TaoCrypt
::
Integer
;
...
...
@@ -836,7 +834,7 @@ DiffieHellman::~DiffieHellman() { delete pimpl_; }
// Client side and view, use server that for p and g
DiffieHellman
::
DiffieHellman
(
const
DiffieHellman
&
that
)
:
pimpl_
(
new
(
ys
)
DHImpl
(
*
that
.
pimpl_
))
:
pimpl_
(
new
DHImpl
(
*
that
.
pimpl_
))
{
pimpl_
->
dh_
.
GenerateKeyPair
(
pimpl_
->
ranPool_
,
pimpl_
->
privateKey_
,
pimpl_
->
publicKey_
);
...
...
@@ -957,7 +955,7 @@ x509* PemToDer(const char* fname, CertType type)
Base64Decoder
b64Dec
(
der
);
uint
sz
=
der
.
size
();
mySTL
::
auto_ptr
<
x509
>
x
(
new
(
ys
)
x509
(
sz
));
mySTL
::
auto_ptr
<
x509
>
x
(
new
x509
(
sz
));
memcpy
(
x
->
use_buffer
(),
der
.
get_buffer
(),
sz
);
fclose
(
file
);
...
...
@@ -971,8 +969,6 @@ x509* PemToDer(const char* fname, CertType type)
template
class
TaoCrypt
::
HMAC
<
TaoCrypt
::
MD5
>;
template
class
TaoCrypt
::
HMAC
<
TaoCrypt
::
SHA
>;
template
class
TaoCrypt
::
HMAC
<
TaoCrypt
::
RIPEMD160
>;
template
class
TaoCrypt
::
Mode_BASE
<
16
>;
template
class
TaoCrypt
::
Mode_BASE
<
8
>;
#endif
#endif // !USE_CRYPTOPP_LIB
extra/yassl/src/handshake.cpp
View file @
424e4ee1
...
...
@@ -362,9 +362,9 @@ void p_hash(output_buffer& result, const output_buffer& secret,
if
(
lastLen
)
times
+=
1
;
if
(
hash
==
md5
)
hmac
.
reset
(
new
(
ys
)
HMAC_MD5
(
secret
.
get_buffer
(),
secret
.
get_size
()));
hmac
.
reset
(
new
HMAC_MD5
(
secret
.
get_buffer
(),
secret
.
get_size
()));
else
hmac
.
reset
(
new
(
ys
)
HMAC_SHA
(
secret
.
get_buffer
(),
secret
.
get_size
()));
hmac
.
reset
(
new
HMAC_SHA
(
secret
.
get_buffer
(),
secret
.
get_size
()));
// A0 = seed
hmac
->
get_digest
(
previous
,
seed
.
get_buffer
(),
seed
.
get_size
());
// A1
uint
lastTime
=
times
-
1
;
...
...
@@ -582,11 +582,11 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
MACAlgorithm
algo
=
ssl
.
getSecurity
().
get_parms
().
mac_algorithm_
;
if
(
algo
==
sha
)
hmac
.
reset
(
new
(
ys
)
HMAC_SHA
(
ssl
.
get_macSecret
(
verify
),
SHA_LEN
));
hmac
.
reset
(
new
HMAC_SHA
(
ssl
.
get_macSecret
(
verify
),
SHA_LEN
));
else
if
(
algo
==
rmd
)
hmac
.
reset
(
new
(
ys
)
HMAC_RMD
(
ssl
.
get_macSecret
(
verify
),
RMD_LEN
));
hmac
.
reset
(
new
HMAC_RMD
(
ssl
.
get_macSecret
(
verify
),
RMD_LEN
));
else
hmac
.
reset
(
new
(
ys
)
HMAC_MD5
(
ssl
.
get_macSecret
(
verify
),
MD5_LEN
));
hmac
.
reset
(
new
HMAC_MD5
(
ssl
.
get_macSecret
(
verify
),
MD5_LEN
));
hmac
->
update
(
seq
,
SEQ_SZ
);
// seq_num
inner
[
0
]
=
content
;
// type
...
...
@@ -687,7 +687,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
// make sure we have enough input in buffer to process this record
if
(
hdr
.
length_
>
buffer
.
get_remaining
())
{
uint
sz
=
buffer
.
get_remaining
()
+
RECORD_HEADER
;
buffered
.
reset
(
new
(
ys
)
input_buffer
(
sz
,
buffer
.
get_buffer
()
+
buffered
.
reset
(
new
input_buffer
(
sz
,
buffer
.
get_buffer
()
+
buffer
.
get_current
()
-
RECORD_HEADER
,
sz
));
break
;
}
...
...
@@ -760,7 +760,7 @@ void sendClientKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader
rlHeader
;
HandShakeHeader
hsHeader
;
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildHeaders
(
ssl
,
hsHeader
,
rlHeader
,
ck
);
buildOutput
(
*
out
.
get
(),
rlHeader
,
hsHeader
,
ck
);
hashHandShake
(
ssl
,
*
out
.
get
());
...
...
@@ -781,7 +781,7 @@ void sendServerKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader
rlHeader
;
HandShakeHeader
hsHeader
;
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildHeaders
(
ssl
,
hsHeader
,
rlHeader
,
sk
);
buildOutput
(
*
out
.
get
(),
rlHeader
,
hsHeader
,
sk
);
hashHandShake
(
ssl
,
*
out
.
get
());
...
...
@@ -806,7 +806,7 @@ void sendChangeCipher(SSL& ssl, BufferOutput buffer)
ChangeCipherSpec
ccs
;
RecordLayerHeader
rlHeader
;
buildHeader
(
ssl
,
rlHeader
,
ccs
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildOutput
(
*
out
.
get
(),
rlHeader
,
ccs
);
if
(
buffer
==
buffered
)
...
...
@@ -823,7 +823,7 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer)
Finished
fin
;
buildFinished
(
ssl
,
fin
,
side
==
client_end
?
client
:
server
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
cipherFinished
(
ssl
,
fin
,
*
out
.
get
());
// hashes handshake
if
(
ssl
.
getSecurity
().
get_resuming
())
{
...
...
@@ -907,7 +907,7 @@ void sendServerHello(SSL& ssl, BufferOutput buffer)
ServerHello
sh
(
ssl
.
getSecurity
().
get_connection
().
version_
);
RecordLayerHeader
rlHeader
;
HandShakeHeader
hsHeader
;
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildServerHello
(
ssl
,
sh
);
ssl
.
set_random
(
sh
.
get_random
(),
server_end
);
...
...
@@ -930,7 +930,7 @@ void sendServerHelloDone(SSL& ssl, BufferOutput buffer)
ServerHelloDone
shd
;
RecordLayerHeader
rlHeader
;
HandShakeHeader
hsHeader
;
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildHeaders
(
ssl
,
hsHeader
,
rlHeader
,
shd
);
buildOutput
(
*
out
.
get
(),
rlHeader
,
hsHeader
,
shd
);
...
...
@@ -951,7 +951,7 @@ void sendCertificate(SSL& ssl, BufferOutput buffer)
Certificate
cert
(
ssl
.
getCrypto
().
get_certManager
().
get_cert
());
RecordLayerHeader
rlHeader
;
HandShakeHeader
hsHeader
;
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildHeaders
(
ssl
,
hsHeader
,
rlHeader
,
cert
);
buildOutput
(
*
out
.
get
(),
rlHeader
,
hsHeader
,
cert
);
...
...
@@ -973,7 +973,7 @@ void sendCertificateRequest(SSL& ssl, BufferOutput buffer)
request
.
Build
();
RecordLayerHeader
rlHeader
;
HandShakeHeader
hsHeader
;
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildHeaders
(
ssl
,
hsHeader
,
rlHeader
,
request
);
buildOutput
(
*
out
.
get
(),
rlHeader
,
hsHeader
,
request
);
...
...
@@ -995,7 +995,7 @@ void sendCertificateVerify(SSL& ssl, BufferOutput buffer)
verify
.
Build
(
ssl
);
RecordLayerHeader
rlHeader
;
HandShakeHeader
hsHeader
;
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
(
ys
)
output_buffer
);
mySTL
::
auto_ptr
<
output_buffer
>
out
(
new
output_buffer
);
buildHeaders
(
ssl
,
hsHeader
,
rlHeader
,
verify
);
buildOutput
(
*
out
.
get
(),
rlHeader
,
hsHeader
,
verify
);
...
...
extra/yassl/src/ssl.cpp
View file @
424e4ee1
...
...
@@ -443,7 +443,7 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type)
fseek
(
input
,
0
,
SEEK_END
);
long
sz
=
ftell
(
input
);
rewind
(
input
);
x
=
new
(
ys
)
x509
(
sz
);
// takes ownership
x
=
new
x509
(
sz
);
// takes ownership
size_t
bytes
=
fread
(
x
->
use_buffer
(),
sz
,
1
,
input
);
if
(
bytes
!=
1
)
{
fclose
(
input
);
...
...
@@ -663,7 +663,7 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal)
if
(
!
retVal
)
{
created
=
true
;
bn
.
reset
(
new
(
ys
)
BIGNUM
);
bn
.
reset
(
new
BIGNUM
);
retVal
=
bn
.
get
();
}
...
...
extra/yassl/src/yassl_imp.cpp
View file @
424e4ee1
...
...
@@ -134,10 +134,10 @@ void DH_Server::build(SSL& ssl)
const
CertManager
&
cert
=
ssl
.
getCrypto
().
get_certManager
();
if
(
ssl
.
getSecurity
().
get_parms
().
sig_algo_
==
rsa_sa_algo
)
auth
.
reset
(
new
(
ys
)
RSA
(
cert
.
get_privateKey
(),
auth
.
reset
(
new
RSA
(
cert
.
get_privateKey
(),
cert
.
get_privateKeyLength
(),
false
));
else
{
auth
.
reset
(
new
(
ys
)
DSS
(
cert
.
get_privateKey
(),
auth
.
reset
(
new
DSS
(
cert
.
get_privateKey
(),
cert
.
get_privateKeyLength
(),
false
));
sigSz
+=
DSS_ENCODED_EXTRA
;
}
...
...
@@ -168,7 +168,7 @@ void DH_Server::build(SSL& ssl)
byte
hash
[
FINISHED_SZ
];
MD5
md5
;
SHA
sha
;
signature_
=
new
(
ys
)
byte
[
sigSz
];
signature_
=
new
byte
[
sigSz
];
const
Connection
&
conn
=
ssl
.
getSecurity
().
get_connection
();
// md5
...
...
@@ -199,7 +199,7 @@ void DH_Server::build(SSL& ssl)
tmp
.
write
(
signature_
,
sigSz
);
// key message
keyMessage_
=
new
(
ys
)
opaque
[
length_
];
keyMessage_
=
new
opaque
[
length_
];
memcpy
(
keyMessage_
,
tmp
.
get_buffer
(),
tmp
.
get_size
());
}
...
...
@@ -253,7 +253,7 @@ opaque* EncryptedPreMasterSecret::get_clientKey() const
void
EncryptedPreMasterSecret
::
alloc
(
int
sz
)
{
length_
=
sz
;
secret_
=
new
(
ys
)
opaque
[
sz
];
secret_
=
new
opaque
[
sz
];
}
...
...
@@ -303,7 +303,7 @@ opaque* ClientDiffieHellmanPublic::get_clientKey() const
void
ClientDiffieHellmanPublic
::
alloc
(
int
sz
,
bool
offset
)
{
length_
=
sz
+
(
offset
?
KEY_OFFSET
:
0
);
Yc_
=
new
(
ys
)
opaque
[
length_
];
Yc_
=
new
opaque
[
length_
];
}
...
...
@@ -348,7 +348,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
tmp
[
1
]
=
input
[
AUTO
];
ato16
(
tmp
,
length
);
signature_
=
new
(
ys
)
byte
[
length
];
signature_
=
new
byte
[
length
];
input
.
read
(
signature_
,
length
);
// verify signature
...
...
@@ -386,7 +386,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
}
// save input
ssl
.
useCrypto
().
SetDH
(
new
(
ys
)
DiffieHellman
(
parms_
.
get_p
(),
ssl
.
useCrypto
().
SetDH
(
new
DiffieHellman
(
parms_
.
get_p
(),
parms_
.
get_pSize
(),
parms_
.
get_g
(),
parms_
.
get_gSize
(),
parms_
.
get_pub
(),
parms_
.
get_pubSize
(),
ssl
.
getCrypto
().
get_random
()));
...
...
@@ -928,7 +928,7 @@ void Data::Process(input_buffer& input, SSL& ssl)
// read data
if
(
dataSz
)
{
input_buffer
*
data
;
ssl
.
addData
(
data
=
new
(
ys
)
input_buffer
(
dataSz
));
ssl
.
addData
(
data
=
new
input_buffer
(
dataSz
));
input
.
read
(
data
->
get_buffer
(),
dataSz
);
data
->
add_size
(
dataSz
);
...
...
@@ -1025,7 +1025,7 @@ void Certificate::Process(input_buffer& input, SSL& ssl)
c24to32
(
tmp
,
cert_sz
);
x509
*
myCert
;
cm
.
AddPeerCert
(
myCert
=
new
(
ys
)
x509
(
cert_sz
));
cm
.
AddPeerCert
(
myCert
=
new
x509
(
cert_sz
));
input
.
read
(
myCert
->
use_buffer
(),
myCert
->
get_length
());
list_sz
-=
cert_sz
+
CERT_HEADER
;
...
...
@@ -1111,21 +1111,21 @@ const opaque* ServerDHParams::get_pub() const
opaque
*
ServerDHParams
::
alloc_p
(
int
sz
)
{
p_
=
new
(
ys
)
opaque
[
pSz_
=
sz
];
p_
=
new
opaque
[
pSz_
=
sz
];
return
p_
;
}
opaque
*
ServerDHParams
::
alloc_g
(
int
sz
)
{
g_
=
new
(
ys
)
opaque
[
gSz_
=
sz
];
g_
=
new
opaque
[
gSz_
=
sz
];
return
g_
;
}
opaque
*
ServerDHParams
::
alloc_pub
(
int
sz
)
{
Ys_
=
new
(
ys
)
opaque
[
pubSz_
=
sz
];
Ys_
=
new
opaque
[
pubSz_
=
sz
];
return
Ys_
;
}
...
...
@@ -1537,7 +1537,7 @@ void CertificateRequest::Build()
for
(
int
j
=
0
;
j
<
authCount
;
j
++
)
{
int
sz
=
REQUEST_HEADER
+
MIN_DIS_SIZE
;
DistinguishedName
dn
;
certificate_authorities_
.
push_back
(
dn
=
new
(
ys
)
byte
[
sz
]);
certificate_authorities_
.
push_back
(
dn
=
new
byte
[
sz
]);
opaque
tmp
[
REQUEST_HEADER
];
c16toa
(
MIN_DIS_SIZE
,
tmp
);
...
...
@@ -1584,7 +1584,7 @@ input_buffer& operator>>(input_buffer& input, CertificateRequest& request)
ato16
(
tmp
,
dnSz
);
DistinguishedName
dn
;
request
.
certificate_authorities_
.
push_back
(
dn
=
new
(
ys
)
request
.
certificate_authorities_
.
push_back
(
dn
=
new
byte
[
REQUEST_HEADER
+
dnSz
]);
memcpy
(
dn
,
tmp
,
REQUEST_HEADER
);
input
.
read
(
&
dn
[
REQUEST_HEADER
],
dnSz
);
...
...
@@ -1665,7 +1665,7 @@ void CertificateVerify::Build(SSL& ssl)
RSA
rsa
(
cert
.
get_privateKey
(),
cert
.
get_privateKeyLength
(),
false
);
sz
=
rsa
.
get_cipherLength
()
+
VERIFY_HEADER
;
sig
.
reset
(
new
(
ys
)
byte
[
sz
]);
sig
.
reset
(
new
byte
[
sz
]);
c16toa
(
sz
-
VERIFY_HEADER
,
len
);
memcpy
(
sig
.
get
(),
len
,
VERIFY_HEADER
);
...
...
@@ -1676,7 +1676,7 @@ void CertificateVerify::Build(SSL& ssl)
DSS
dss
(
cert
.
get_privateKey
(),
cert
.
get_privateKeyLength
(),
false
);
sz
=
DSS_SIG_SZ
+
DSS_ENCODED_EXTRA
+
VERIFY_HEADER
;
sig
.
reset
(
new
(
ys
)
byte
[
sz
]);
sig
.
reset
(
new
byte
[
sz
]);
c16toa
(
sz
-
VERIFY_HEADER
,
len
);
memcpy
(
sig
.
get
(),
len
,
VERIFY_HEADER
);
...
...
@@ -1714,7 +1714,7 @@ input_buffer& operator>>(input_buffer& input, CertificateVerify& request)
ato16
(
tmp
,
sz
);
request
.
set_length
(
sz
);
request
.
signature_
=
new
(
ys
)
byte
[
sz
];
request
.
signature_
=
new
byte
[
sz
];
input
.
read
(
request
.
signature_
,
sz
);
return
input
;
...
...
@@ -1975,7 +1975,7 @@ Connection::~Connection()
void
Connection
::
AllocPreSecret
(
uint
sz
)
{
pre_master_secret_
=
new
(
ys
)
opaque
[
pre_secret_len_
=
sz
];
pre_master_secret_
=
new
opaque
[
pre_secret_len_
=
sz
];
}
...
...
@@ -2011,35 +2011,35 @@ void Connection::CleanPreMaster()
// Create functions for message factory
Message
*
CreateCipherSpec
()
{
return
new
(
ys
)
ChangeCipherSpec
;
}
Message
*
CreateAlert
()
{
return
new
(
ys
)
Alert
;
}
Message
*
CreateHandShake
()
{
return
new
(
ys
)
HandShakeHeader
;
}
Message
*
CreateData
()
{
return
new
(
ys
)
Data
;
}
Message
*
CreateCipherSpec
()
{
return
new
ChangeCipherSpec
;
}
Message
*
CreateAlert
()
{
return
new
Alert
;
}
Message
*
CreateHandShake
()
{
return
new
HandShakeHeader
;
}
Message
*
CreateData
()
{
return
new
Data
;
}
// Create functions for handshake factory
HandShakeBase
*
CreateHelloRequest
()
{
return
new
(
ys
)
HelloRequest
;
}
HandShakeBase
*
CreateClientHello
()
{
return
new
(
ys
)
ClientHello
;
}
HandShakeBase
*
CreateServerHello
()
{
return
new
(
ys
)
ServerHello
;
}
HandShakeBase
*
CreateCertificate
()
{
return
new
(
ys
)
Certificate
;
}
HandShakeBase
*
CreateServerKeyExchange
()
{
return
new
(
ys
)
ServerKeyExchange
;}
HandShakeBase
*
CreateCertificateRequest
()
{
return
new
(
ys
)
HandShakeBase
*
CreateHelloRequest
()
{
return
new
HelloRequest
;
}
HandShakeBase
*
CreateClientHello
()
{
return
new
ClientHello
;
}
HandShakeBase
*
CreateServerHello
()
{
return
new
ServerHello
;
}
HandShakeBase
*
CreateCertificate
()
{
return
new
Certificate
;
}
HandShakeBase
*
CreateServerKeyExchange
()
{
return
new
ServerKeyExchange
;}
HandShakeBase
*
CreateCertificateRequest
()
{
return
new
CertificateRequest
;
}
HandShakeBase
*
CreateServerHelloDone
()
{
return
new
(
ys
)
ServerHelloDone
;
}
HandShakeBase
*
CreateCertificateVerify
()
{
return
new
(
ys
)
CertificateVerify
;}
HandShakeBase
*
CreateClientKeyExchange
()
{
return
new
(
ys
)
ClientKeyExchange
;}
HandShakeBase
*
CreateFinished
()
{
return
new
(
ys
)
Finished
;
}
HandShakeBase
*
CreateServerHelloDone
()
{
return
new
ServerHelloDone
;
}
HandShakeBase
*
CreateCertificateVerify
()
{
return
new
CertificateVerify
;}
HandShakeBase
*
CreateClientKeyExchange
()
{
return
new
ClientKeyExchange
;}
HandShakeBase
*
CreateFinished
()
{
return
new
Finished
;
}
// Create functions for server key exchange factory
ServerKeyBase
*
CreateRSAServerKEA
()
{
return
new
(
ys
)
RSA_Server
;
}
ServerKeyBase
*
CreateDHServerKEA
()
{
return
new
(
ys
)
DH_Server
;
}
ServerKeyBase
*
CreateFortezzaServerKEA
()
{
return
new
(
ys
)
Fortezza_Server
;
}
ServerKeyBase
*
CreateRSAServerKEA
()
{
return
new
RSA_Server
;
}
ServerKeyBase
*
CreateDHServerKEA
()
{
return
new
DH_Server
;
}
ServerKeyBase
*
CreateFortezzaServerKEA
()
{
return
new
Fortezza_Server
;
}
// Create functions for client key exchange factory
ClientKeyBase
*
CreateRSAClient
()
{
return
new
(
ys
)
ClientKeyBase
*
CreateRSAClient
()
{
return
new
EncryptedPreMasterSecret
;
}
ClientKeyBase
*
CreateDHClient
()
{
return
new
(
ys
)
ClientKeyBase
*
CreateDHClient
()
{
return
new
ClientDiffieHellmanPublic
;
}
ClientKeyBase
*
CreateFortezzaClient
()
{
return
new
(
ys
)
FortezzaKeys
;
}
ClientKeyBase
*
CreateFortezzaClient
()
{
return
new
FortezzaKeys
;
}
// Constructor calls this to Register compile time callbacks
...
...
@@ -2115,4 +2115,3 @@ template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::output_buffer*>:
template
yaSSL
::
del_ptr_zero
mySTL
::
for_each
<
mySTL
::
list
<
yaSSL
::
x509
*
>
::
iterator
,
yaSSL
::
del_ptr_zero
>
(
mySTL
::
list
<
yaSSL
::
x509
*>::
iterator
,
mySTL
::
list
<
yaSSL
::
x509
*>::
iterator
,
yaSSL
::
del_ptr_zero
);
}
#endif
extra/yassl/src/yassl_int.cpp
View file @
424e4ee1
This diff is collapsed.
Click to expand it.
extra/yassl/taocrypt/include/aes.hpp
View file @
424e4ee1
...
...
@@ -37,11 +37,12 @@ enum { AES_BLOCK_SIZE = 16 };
// AES encryption and decryption, see FIPS-197
class
AES
:
public
Mode_BASE
<
AES_BLOCK_SIZE
>
{
class
AES
:
public
Mode_BASE
{
public:
enum
{
BLOCK_SIZE
=
AES_BLOCK_SIZE
};
AES
(
CipherDir
DIR
,
Mode
MODE
)
:
dir_
(
DIR
),
mode_
(
MODE
)
{}
AES
(
CipherDir
DIR
,
Mode
MODE
)
:
Mode_BASE
(
BLOCK_SIZE
),
dir_
(
DIR
),
mode_
(
MODE
)
{}
void
Process
(
byte
*
,
const
byte
*
,
word32
);
void
SetKey
(
const
byte
*
iv
,
word32
sz
,
CipherDir
fake
=
ENCRYPTION
);
...
...
extra/yassl/taocrypt/include/algebra.hpp
View file @
424e4ee1
...
...
@@ -24,11 +24,10 @@
#ifndef TAO_CRYPT_ALGEBRA_HPP
#define TAO_CRYPT_ALGEBRA_HPP
#include "
misc
.hpp"
#include "
integer
.hpp"
namespace
TaoCrypt
{
class
Integer
;
// "const Element&" returned by member functions are references
// to internal data members. Since each object may have only
...
...
@@ -38,11 +37,11 @@ class Integer;
// But this should be fine:
// abcd = group.Add(a, group.Add(b, group.Add(c,d));
//
!
Abstract Group
template
<
class
T
>
class
TAOCRYPT_NO_VTABLE
AbstractGroup
// Abstract Group
class
TAOCRYPT_NO_VTABLE
AbstractGroup
{
public:
typedef
T
Element
;
typedef
Integer
Element
;
virtual
~
AbstractGroup
()
{}
...
...
@@ -65,15 +64,14 @@ public:
const
Integer
*
exponents
,
unsigned
int
exponentsCount
)
const
;
};
//! Abstract Ring
template
<
class
T
>
class
TAOCRYPT_NO_VTABLE
AbstractRing
:
public
AbstractGroup
<
T
>
// Abstract Ring
class
TAOCRYPT_NO_VTABLE
AbstractRing
:
public
AbstractGroup
{
public:
typedef
T
Element
;
typedef
Integer
Element
;
AbstractRing
()
{
m_mg
.
m_pRing
=
this
;}
AbstractRing
(
const
AbstractRing
&
source
)
{
m_mg
.
m_pRing
=
this
;}
AbstractRing
(
const
AbstractRing
&
source
)
:
AbstractGroup
()
{
m_mg
.
m_pRing
=
this
;}
AbstractRing
&
operator
=
(
const
AbstractRing
&
source
)
{
return
*
this
;}
virtual
bool
IsUnit
(
const
Element
&
a
)
const
=
0
;
...
...
@@ -91,14 +89,14 @@ public:
virtual
void
SimultaneousExponentiate
(
Element
*
results
,
const
Element
&
,
const
Integer
*
exponents
,
unsigned
int
exponentsCount
)
const
;
virtual
const
AbstractGroup
<
T
>
&
MultiplicativeGroup
()
const
virtual
const
AbstractGroup
&
MultiplicativeGroup
()
const
{
return
m_mg
;}
private:
class
MultiplicativeGroupT
:
public
AbstractGroup
<
T
>
class
MultiplicativeGroupT
:
public
AbstractGroup
{
public:
const
AbstractRing
<
T
>
&
GetRing
()
const
const
AbstractRing
&
GetRing
()
const
{
return
*
m_pRing
;}
bool
Equal
(
const
Element
&
a
,
const
Element
&
b
)
const
...
...
@@ -137,44 +135,19 @@ private:
{
GetRing
().
SimultaneousExponentiate
(
results
,
base
,
exponents
,
exponentsCount
);}
const
AbstractRing
<
T
>
*
m_pRing
;
const
AbstractRing
*
m_pRing
;
};
MultiplicativeGroupT
m_mg
;
};
// ********************************************************
//
! Base and Exponent
template
<
class
T
,
class
E
=
Integer
>
struct
BaseAndExponent
//
Abstract Euclidean Domain
class
TAOCRYPT_NO_VTABLE
AbstractEuclideanDomain
:
public
AbstractRing
{
public:
BaseAndExponent
()
{}
BaseAndExponent
(
const
T
&
base
,
const
E
&
exponent
)
:
base
(
base
),
exponent
(
exponent
)
{}
bool
operator
<
(
const
BaseAndExponent
<
T
,
E
>
&
rhs
)
const
{
return
exponent
<
rhs
.
exponent
;}
T
base
;
E
exponent
;
};
// VC60 workaround: incomplete member template support
template
<
class
Element
,
class
Iterator
>
Element
GeneralCascadeMultiplication
(
const
AbstractGroup
<
Element
>
&
group
,
Iterator
begin
,
Iterator
end
);
template
<
class
Element
,
class
Iterator
>
Element
GeneralCascadeExponentiation
(
const
AbstractRing
<
Element
>
&
ring
,
Iterator
begin
,
Iterator
end
);
// ********************************************************
//! Abstract Euclidean Domain
template
<
class
T
>
class
TAOCRYPT_NO_VTABLE
AbstractEuclideanDomain
:
public
AbstractRing
<
T
>
{
public:
typedef
T
Element
;
typedef
Integer
Element
;
virtual
void
DivisionAlgorithm
(
Element
&
r
,
Element
&
q
,
const
Element
&
a
,
const
Element
&
d
)
const
=
0
;
...
...
@@ -186,13 +159,12 @@ protected:
mutable
Element
result
;
};
// ********************************************************
//
!
EuclideanDomainOf
template
<
class
T
>
class
EuclideanDomainOf
:
public
AbstractEuclideanDomain
<
T
>
// EuclideanDomainOf
class
EuclideanDomainOf
:
public
AbstractEuclideanDomain
{
public:
typedef
T
Element
;
typedef
Integer
Element
;
EuclideanDomainOf
()
{}
...
...
@@ -249,68 +221,8 @@ private:
mutable
Element
result
;
};
//! Quotient Ring
template
<
class
T
>
class
QuotientRing
:
public
AbstractRing
<
typename
T
::
Element
>
{
public:
typedef
T
EuclideanDomain
;
typedef
typename
T
::
Element
Element
;
QuotientRing
(
const
EuclideanDomain
&
domain
,
const
Element
&
modulus
)
:
m_domain
(
domain
),
m_modulus
(
modulus
)
{}
const
EuclideanDomain
&
GetDomain
()
const
{
return
m_domain
;}
const
Element
&
GetModulus
()
const
{
return
m_modulus
;}
bool
Equal
(
const
Element
&
a
,
const
Element
&
b
)
const
{
return
m_domain
.
Equal
(
m_domain
.
Mod
(
m_domain
.
Subtract
(
a
,
b
),
m_modulus
),
m_domain
.
Identity
());}
const
Element
&
Identity
()
const
{
return
m_domain
.
Identity
();}
const
Element
&
Add
(
const
Element
&
a
,
const
Element
&
b
)
const
{
return
m_domain
.
Add
(
a
,
b
);}
Element
&
Accumulate
(
Element
&
a
,
const
Element
&
b
)
const
{
return
m_domain
.
Accumulate
(
a
,
b
);}
const
Element
&
Inverse
(
const
Element
&
a
)
const
{
return
m_domain
.
Inverse
(
a
);}
const
Element
&
Subtract
(
const
Element
&
a
,
const
Element
&
b
)
const
{
return
m_domain
.
Subtract
(
a
,
b
);}
Element
&
Reduce
(
Element
&
a
,
const
Element
&
b
)
const
{
return
m_domain
.
Reduce
(
a
,
b
);}
const
Element
&
Double
(
const
Element
&
a
)
const
{
return
m_domain
.
Double
(
a
);}
bool
IsUnit
(
const
Element
&
a
)
const
{
return
m_domain
.
IsUnit
(
m_domain
.
Gcd
(
a
,
m_modulus
));}
const
Element
&
MultiplicativeIdentity
()
const
{
return
m_domain
.
MultiplicativeIdentity
();}
const
Element
&
Multiply
(
const
Element
&
a
,
const
Element
&
b
)
const
{
return
m_domain
.
Mod
(
m_domain
.
Multiply
(
a
,
b
),
m_modulus
);}
const
Element
&
Square
(
const
Element
&
a
)
const
{
return
m_domain
.
Mod
(
m_domain
.
Square
(
a
),
m_modulus
);}
const
Element
&
MultiplicativeInverse
(
const
Element
&
a
)
const
;
protected:
EuclideanDomain
m_domain
;
Element
m_modulus
;
};
}
// namespace
#endif // TAO_CRYPT_ALGEBRA_HPP
extra/yassl/taocrypt/include/block.hpp
View file @
424e4ee1
...
...
@@ -34,10 +34,6 @@
#include <stddef.h> // ptrdiff_t
#if defined(_MSC_VER) && defined(_CRTAPI1)
#define TAOCRYPT_MSVCRT6
#endif
namespace
TaoCrypt
{
...
...
@@ -47,13 +43,13 @@ template<class T>
class
AllocatorBase
{
public:
typedef
T
value_type
;
typedef
size_t
size_type
;
typedef
ptrdiff_t
difference_type
;
typedef
T
*
pointer
;
typedef
const
T
*
const_pointer
;
typedef
T
&
reference
;
typedef
const
T
&
const_reference
;
typedef
T
value_type
;
typedef
size_t
size_type
;
typedef
ptrdiff_t
difference_type
;
typedef
T
*
pointer
;
typedef
const
T
*
const_pointer
;
typedef
T
&
reference
;
typedef
const
T
&
const_reference
;
pointer
address
(
reference
r
)
const
{
return
(
&
r
);}
const_pointer
address
(
const_reference
r
)
const
{
return
(
&
r
);
}
...
...
@@ -104,7 +100,7 @@ public:
CheckSize
(
n
);
if
(
n
==
0
)
return
0
;
return
new
(
tc
)
T
[
n
];
return
new
T
[
n
];
}
void
deallocate
(
void
*
p
,
size_type
n
)
...
...
extra/yassl/taocrypt/include/des.hpp
View file @
424e4ee1
...
...
@@ -36,12 +36,13 @@ namespace TaoCrypt {
enum
{
DES_BLOCK_SIZE
=
8
};
// Base for all DES types
class
DES_BASE
:
public
Mode_BASE
<
DES_BLOCK_SIZE
>
{
class
DES_BASE
:
public
Mode_BASE
{
public:
enum
{
BLOCK_SIZE
=
DES_BLOCK_SIZE
,
KEY_SIZE
=
32
,
BOXES
=
8
,
BOX_SIZE
=
64
};
DES_BASE
(
CipherDir
DIR
,
Mode
MODE
)
:
dir_
(
DIR
),
mode_
(
MODE
)
{}
DES_BASE
(
CipherDir
DIR
,
Mode
MODE
)
:
Mode_BASE
(
BLOCK_SIZE
),
dir_
(
DIR
),
mode_
(
MODE
)
{}
void
Process
(
byte
*
,
const
byte
*
,
word32
);
protected:
...
...
extra/yassl/taocrypt/include/error.hpp
View file @
424e4ee1
...
...
@@ -65,7 +65,8 @@ UNKOWN_HASH_E = 1034, // "unknown hash OID"
DSA_SZ_E
=
1035
,
// "bad DSA r or s size"
BEFORE_DATE_E
=
1036
,
// "before date in the future"
AFTER_DATE_E
=
1037
,
// "after date in the past"
SIG_CONFIRM_E
=
1038
// "bad signature confirmation"
SIG_CONFIRM_E
=
1038
,
// "bad self signature confirmation"
SIG_OTHER_E
=
1039
// "bad other signature confirmation"
};
...
...
extra/yassl/taocrypt/include/hash.hpp
View file @
424e4ee1
...
...
@@ -50,7 +50,7 @@ public:
class
HASHwithTransform
:
public
HASH
{
public:
HASHwithTransform
(
word32
digSz
,
word32
buffSz
)
:
digest_
(
new
(
tc
)
word32
[
digSz
]),
buffer_
(
new
(
tc
)
byte
[
buffSz
])
{}
:
digest_
(
new
word32
[
digSz
]),
buffer_
(
new
byte
[
buffSz
])
{}
virtual
~
HASHwithTransform
()
{
delete
[]
buffer_
;
delete
[]
digest_
;
}
virtual
ByteOrder
getByteOrder
()
const
=
0
;
...
...
extra/yassl/taocrypt/include/integer.hpp
View file @
424e4ee1
...
...
@@ -29,8 +29,8 @@
#include "block.hpp"
#include "random.hpp"
#include "file.hpp"
#include <string.h>
#include "algorithm.hpp" // mySTL::swap
#include <string.h>
#ifdef TAOCRYPT_X86ASM_AVAILABLE
...
...
@@ -128,9 +128,6 @@ public:
Integer
(
signed
long
value
);
Integer
(
Sign
s
,
word
highWord
,
word
lowWord
);
explicit
Integer
(
const
char
*
str
);
explicit
Integer
(
const
wchar_t
*
str
);
// BER Decode Source
explicit
Integer
(
Source
&
);
...
...
@@ -254,15 +251,13 @@ public:
private:
friend
class
ModularArithmetic
;
friend
class
MontgomeryRepresentation
;
friend
class
HalfMontgomeryRepresentation
;
Integer
(
word
value
,
unsigned
int
length
);
static
const
Integer
zero
;
static
const
Integer
one
;
static
const
Integer
two
;
int
PositiveCompare
(
const
Integer
&
t
)
const
;
friend
void
PositiveAdd
(
Integer
&
sum
,
const
Integer
&
a
,
const
Integer
&
b
);
friend
void
PositiveSubtract
(
Integer
&
diff
,
const
Integer
&
a
,
const
Integer
&
b
);
...
...
@@ -308,6 +303,7 @@ inline void swap(Integer &a, Integer &b)
Integer
CRT
(
const
Integer
&
xp
,
const
Integer
&
p
,
const
Integer
&
xq
,
const
Integer
&
q
,
const
Integer
&
u
);
inline
Integer
ModularExponentiation
(
const
Integer
&
a
,
const
Integer
&
e
,
const
Integer
&
m
)
{
...
...
extra/yassl/taocrypt/include/misc.hpp
View file @
424e4ee1
...
...
@@ -28,17 +28,6 @@
#include <assert.h>
#include <string.h>
namespace
TaoCrypt
{
// library allocation
struct
new_t
{};
// TaoCrypt New type
extern
new_t
tc
;
// pass in parameter
}
// namespace TaoCrypt
void
*
operator
new
(
size_t
,
TaoCrypt
::
new_t
);
void
*
operator
new
[](
size_t
,
TaoCrypt
::
new_t
);
namespace
TaoCrypt
{
...
...
extra/yassl/taocrypt/include/modarith.hpp
View file @
424e4ee1
...
...
@@ -27,14 +27,13 @@
#define TAO_CRYPT_MODARITH_HPP
#include "misc.hpp"
#include "integer.hpp"
#include "algebra.hpp"
namespace
TaoCrypt
{
//
!
ModularArithmetic
class
ModularArithmetic
:
public
AbstractRing
<
Integer
>
// ModularArithmetic
class
ModularArithmetic
:
public
AbstractRing
{
public:
...
...
@@ -45,7 +44,7 @@ public:
:
modulus
(
modulus
),
result
((
word
)
0
,
modulus
.
reg_
.
size
())
{}
ModularArithmetic
(
const
ModularArithmetic
&
ma
)
:
AbstractRing
<
Integer
>
(),
:
AbstractRing
(),
modulus
(
ma
.
modulus
),
result
((
word
)
0
,
modulus
.
reg_
.
size
())
{}
const
Integer
&
GetModulus
()
const
{
return
modulus
;}
...
...
@@ -149,12 +148,12 @@ public:
Integer
CascadeExponentiate
(
const
Integer
&
x
,
const
Integer
&
e1
,
const
Integer
&
y
,
const
Integer
&
e2
)
const
{
return
AbstractRing
<
Integer
>
::
CascadeExponentiate
(
x
,
e1
,
y
,
e2
);}
{
return
AbstractRing
::
CascadeExponentiate
(
x
,
e1
,
y
,
e2
);}
void
SimultaneousExponentiate
(
Element
*
results
,
const
Element
&
base
,
const
Integer
*
exponents
,
unsigned
int
exponentsCount
)
const
{
AbstractRing
<
Integer
>
::
SimultaneousExponentiate
(
results
,
base
,
exponents
,
exponentsCount
);}
{
AbstractRing
::
SimultaneousExponentiate
(
results
,
base
,
exponents
,
exponentsCount
);}
private:
Integer
u
;
...
...
extra/yassl/taocrypt/include/modes.hpp
View file @
424e4ee1
...
...
@@ -56,10 +56,11 @@ private:
// Mode Base for block ciphers, static size
template
<
int
BLOCK_SIZE
>
class
Mode_BASE
{
public:
Mode_BASE
()
{}
enum
{
MaxBlockSz
=
16
};
explicit
Mode_BASE
(
int
sz
)
:
blockSz_
(
sz
)
{
assert
(
sz
<=
MaxBlockSz
);
}
virtual
~
Mode_BASE
()
{}
virtual
void
ProcessAndXorBlock
(
const
byte
*
,
const
byte
*
,
byte
*
)
const
=
0
;
...
...
@@ -68,10 +69,11 @@ public:
void
CBC_Encrypt
(
byte
*
,
const
byte
*
,
word32
);
void
CBC_Decrypt
(
byte
*
,
const
byte
*
,
word32
);
void
SetIV
(
const
byte
*
iv
)
{
memcpy
(
reg_
,
iv
,
BLOCK_SIZE
);
}
void
SetIV
(
const
byte
*
iv
)
{
memcpy
(
reg_
,
iv
,
blockSz_
);
}
private:
byte
reg_
[
BLOCK_SIZE
];
byte
tmp_
[
BLOCK_SIZE
];
byte
reg_
[
MaxBlockSz
];
byte
tmp_
[
MaxBlockSz
];
int
blockSz_
;
Mode_BASE
(
const
Mode_BASE
&
);
// hide copy
Mode_BASE
&
operator
=
(
const
Mode_BASE
&
);
// and assign
...
...
@@ -79,51 +81,48 @@ private:
// ECB Process blocks
template
<
int
BLOCK_SIZE
>
void
Mode_BASE
<
BLOCK_SIZE
>::
ECB_Process
(
byte
*
out
,
const
byte
*
in
,
word32
sz
)
inline
void
Mode_BASE
::
ECB_Process
(
byte
*
out
,
const
byte
*
in
,
word32
sz
)
{
word32
blocks
=
sz
/
BLOCK_SIZE
;
word32
blocks
=
sz
/
blockSz_
;
while
(
blocks
--
)
{
ProcessAndXorBlock
(
in
,
0
,
out
);
out
+=
BLOCK_SIZE
;
in
+=
BLOCK_SIZE
;
out
+=
blockSz_
;
in
+=
blockSz_
;
}
}
// CBC Encrypt
template
<
int
BLOCK_SIZE
>
void
Mode_BASE
<
BLOCK_SIZE
>::
CBC_Encrypt
(
byte
*
out
,
const
byte
*
in
,
word32
sz
)
inline
void
Mode_BASE
::
CBC_Encrypt
(
byte
*
out
,
const
byte
*
in
,
word32
sz
)
{
word32
blocks
=
sz
/
BLOCK_SIZE
;
word32
blocks
=
sz
/
blockSz_
;
while
(
blocks
--
)
{
xorbuf
(
reg_
,
in
,
BLOCK_SIZE
);
xorbuf
(
reg_
,
in
,
blockSz_
);
ProcessAndXorBlock
(
reg_
,
0
,
reg_
);
memcpy
(
out
,
reg_
,
BLOCK_SIZE
);
out
+=
BLOCK_SIZE
;
in
+=
BLOCK_SIZE
;
memcpy
(
out
,
reg_
,
blockSz_
);
out
+=
blockSz_
;
in
+=
blockSz_
;
}
}
// CBC Decrypt
template
<
int
BLOCK_SIZE
>
void
Mode_BASE
<
BLOCK_SIZE
>::
CBC_Decrypt
(
byte
*
out
,
const
byte
*
in
,
word32
sz
)
inline
void
Mode_BASE
::
CBC_Decrypt
(
byte
*
out
,
const
byte
*
in
,
word32
sz
)
{
word32
blocks
=
sz
/
BLOCK_SIZE
;
byte
hold
[
BLOCK_SIZE
];
word32
blocks
=
sz
/
blockSz_
;
byte
hold
[
MaxBlockSz
];
while
(
blocks
--
)
{
memcpy
(
tmp_
,
in
,
BLOCK_SIZE
);
memcpy
(
tmp_
,
in
,
blockSz_
);
ProcessAndXorBlock
(
tmp_
,
0
,
out
);
xorbuf
(
out
,
reg_
,
BLOCK_SIZE
);
memcpy
(
hold
,
reg_
,
BLOCK_SIZE
);
// swap reg_ and tmp_
memcpy
(
reg_
,
tmp_
,
BLOCK_SIZE
);
memcpy
(
tmp_
,
hold
,
BLOCK_SIZE
);
out
+=
BLOCK_SIZE
;
in
+=
BLOCK_SIZE
;
xorbuf
(
out
,
reg_
,
blockSz_
);
memcpy
(
hold
,
reg_
,
blockSz_
);
// swap reg_ and tmp_
memcpy
(
reg_
,
tmp_
,
blockSz_
);
memcpy
(
tmp_
,
hold
,
blockSz_
);
out
+=
blockSz_
;
in
+=
blockSz_
;
}
}
...
...
extra/yassl/taocrypt/src/algebra.cpp
View file @
424e4ee1
...
...
@@ -23,60 +23,58 @@
#include "runtime.hpp"
#include "algebra.hpp"
#include "integer.hpp"
#include "vector.hpp" // mySTL::vector (simple)
namespace
TaoCrypt
{
template
<
class
T
>
const
T
&
AbstractGroup
<
T
>::
Double
(
const
Element
&
a
)
const
const
Integer
&
AbstractGroup
::
Double
(
const
Element
&
a
)
const
{
return
Add
(
a
,
a
);
}
template
<
class
T
>
const
T
&
AbstractGroup
<
T
>::
Subtract
(
const
Element
&
a
,
const
Element
&
b
)
const
const
Integer
&
AbstractGroup
::
Subtract
(
const
Element
&
a
,
const
Element
&
b
)
const
{
// make copy of a in case Inverse() overwrites it
Element
a1
(
a
);
return
Add
(
a1
,
Inverse
(
b
));
}
template
<
class
T
>
T
&
AbstractGroup
<
T
>::
Accumulate
(
Element
&
a
,
const
Element
&
b
)
const
Integer
&
AbstractGroup
::
Accumulate
(
Element
&
a
,
const
Element
&
b
)
const
{
return
a
=
Add
(
a
,
b
);
}
template
<
class
T
>
T
&
AbstractGroup
<
T
>::
Reduce
(
Element
&
a
,
const
Element
&
b
)
const
Integer
&
AbstractGroup
::
Reduce
(
Element
&
a
,
const
Element
&
b
)
const
{
return
a
=
Subtract
(
a
,
b
);
}
template
<
class
T
>
const
T
&
AbstractRing
<
T
>
::
Square
(
const
Element
&
a
)
const
const
Integer
&
AbstractRing
::
Square
(
const
Element
&
a
)
const
{
return
Multiply
(
a
,
a
);
}
template
<
class
T
>
const
T
&
AbstractRing
<
T
>::
Divide
(
const
Element
&
a
,
const
Element
&
b
)
const
const
Integer
&
AbstractRing
::
Divide
(
const
Element
&
a
,
const
Element
&
b
)
const
{
// make copy of a in case MultiplicativeInverse() overwrites it
Element
a1
(
a
);
return
Multiply
(
a1
,
MultiplicativeInverse
(
b
));
}
template
<
class
T
>
const
T
&
AbstractEuclideanDomain
<
T
>::
Mod
(
const
Element
&
a
,
const
Element
&
b
)
const
const
Integer
&
AbstractEuclideanDomain
::
Mod
(
const
Element
&
a
,
const
Element
&
b
)
const
{
Element
q
;
DivisionAlgorithm
(
result
,
q
,
a
,
b
);
return
result
;
}
template
<
class
T
>
const
T
&
AbstractEuclideanDomain
<
T
>
::
Gcd
(
const
Element
&
a
,
const
Element
&
b
)
const
const
Integer
&
AbstractEuclideanDomain
::
Gcd
(
const
Element
&
a
,
const
Element
&
b
)
const
{
Element
g
[
3
]
=
{
b
,
a
};
unsigned
int
i0
=
0
,
i1
=
1
,
i2
=
2
;
...
...
@@ -90,45 +88,17 @@ template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a,
return
result
=
g
[
i0
];
}
template
<
class
T
>
const
typename
QuotientRing
<
T
>::
Element
&
QuotientRing
<
T
>::
MultiplicativeInverse
(
const
Element
&
a
)
const
{
Element
g
[
3
]
=
{
m_modulus
,
a
};
#ifdef __BCPLUSPLUS__
// BC++50 workaround
Element
v
[
3
];
v
[
0
]
=
m_domain
.
Identity
();
v
[
1
]
=
m_domain
.
MultiplicativeIdentity
();
#else
Element
v
[
3
]
=
{
m_domain
.
Identity
(),
m_domain
.
MultiplicativeIdentity
()};
#endif
Element
y
;
unsigned
int
i0
=
0
,
i1
=
1
,
i2
=
2
;
while
(
!
Equal
(
g
[
i1
],
Identity
()))
{
// y = g[i0] / g[i1];
// g[i2] = g[i0] % g[i1];
m_domain
.
DivisionAlgorithm
(
g
[
i2
],
y
,
g
[
i0
],
g
[
i1
]);
// v[i2] = v[i0] - (v[i1] * y);
v
[
i2
]
=
m_domain
.
Subtract
(
v
[
i0
],
m_domain
.
Multiply
(
v
[
i1
],
y
));
unsigned
int
t
=
i0
;
i0
=
i1
;
i1
=
i2
;
i2
=
t
;
}
return
m_domain
.
IsUnit
(
g
[
i0
])
?
m_domain
.
Divide
(
v
[
i0
],
g
[
i0
])
:
m_domain
.
Identity
();
}
template
<
class
T
>
T
AbstractGroup
<
T
>::
ScalarMultiply
(
const
Element
&
base
,
const
Integer
&
exponent
)
const
Integer
AbstractGroup
::
ScalarMultiply
(
const
Element
&
base
,
const
Integer
&
exponent
)
const
{
Element
result
;
SimultaneousMultiply
(
&
result
,
base
,
&
exponent
,
1
);
return
result
;
}
template
<
class
T
>
T
AbstractGroup
<
T
>::
CascadeScalarMultiply
(
const
Element
&
x
,
Integer
AbstractGroup
::
CascadeScalarMultiply
(
const
Element
&
x
,
const
Integer
&
e1
,
const
Element
&
y
,
const
Integer
&
e2
)
const
{
const
unsigned
expLen
=
max
(
e1
.
BitCount
(),
e2
.
BitCount
());
...
...
@@ -258,8 +228,8 @@ struct WindowSlider
bool
fastNegate
,
negateNext
,
firstTime
,
finished
;
};
template
<
class
T
>
void
AbstractGroup
<
T
>::
SimultaneousMultiply
(
T
*
results
,
const
T
&
base
,
void
AbstractGroup
::
SimultaneousMultiply
(
Integer
*
results
,
const
Integer
&
base
,
const
Integer
*
expBegin
,
unsigned
int
expCount
)
const
{
mySTL
::
vector
<
mySTL
::
vector
<
Element
>
>
buckets
(
expCount
);
...
...
@@ -321,34 +291,39 @@ void AbstractGroup<T>::SimultaneousMultiply(T *results, const T &base,
}
}
template
<
class
T
>
T
AbstractRing
<
T
>
::
Exponentiate
(
const
Element
&
base
,
const
Integer
&
exponent
)
const
Integer
AbstractRing
::
Exponentiate
(
const
Element
&
base
,
const
Integer
&
exponent
)
const
{
Element
result
;
SimultaneousExponentiate
(
&
result
,
base
,
&
exponent
,
1
);
return
result
;
}
template
<
class
T
>
T
AbstractRing
<
T
>::
CascadeExponentiate
(
const
Element
&
x
,
Integer
AbstractRing
::
CascadeExponentiate
(
const
Element
&
x
,
const
Integer
&
e1
,
const
Element
&
y
,
const
Integer
&
e2
)
const
{
return
MultiplicativeGroup
().
AbstractGroup
<
T
>
::
CascadeScalarMultiply
(
return
MultiplicativeGroup
().
AbstractGroup
::
CascadeScalarMultiply
(
x
,
e1
,
y
,
e2
);
}
template
<
class
Element
,
class
Iterator
>
Element
GeneralCascadeExponentiation
(
const
AbstractRing
<
Element
>
&
ring
,
Iterator
begin
,
Iterator
end
)
{
return
GeneralCascadeMultiplication
<
Element
>
(
ring
.
MultiplicativeGroup
(),
begin
,
end
);
}
template
<
class
T
>
void
AbstractRing
<
T
>::
SimultaneousExponentiate
(
T
*
results
,
const
T
&
base
,
void
AbstractRing
::
SimultaneousExponentiate
(
Integer
*
results
,
const
Integer
&
base
,
const
Integer
*
exponents
,
unsigned
int
expCount
)
const
{
MultiplicativeGroup
().
AbstractGroup
<
T
>
::
SimultaneousMultiply
(
results
,
base
,
MultiplicativeGroup
().
AbstractGroup
::
SimultaneousMultiply
(
results
,
base
,
exponents
,
expCount
);
}
}
// namespace
#ifdef __GNUC__
namespace
mySTL
{
template
TaoCrypt
::
WindowSlider
*
uninit_copy
<
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
>(
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
);
template
vector
<
TaoCrypt
::
Integer
>
*
uninit_fill_n
<
vector
<
TaoCrypt
::
Integer
>*
,
unsigned
int
,
vector
<
TaoCrypt
::
Integer
>
>
(
vector
<
TaoCrypt
::
Integer
>*
,
unsigned
int
,
vector
<
TaoCrypt
::
Integer
>
const
&
);
template
void
destroy
<
TaoCrypt
::
WindowSlider
*
>(
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
);
template
void
destroy
<
vector
<
TaoCrypt
::
Integer
>
*>
(
vector
<
TaoCrypt
::
Integer
>*
,
vector
<
TaoCrypt
::
Integer
>*
);
}
#endif
extra/yassl/taocrypt/src/asn.cpp
View file @
424e4ee1
...
...
@@ -187,7 +187,7 @@ PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0)
void
PublicKey
::
SetSize
(
word32
s
)
{
sz_
=
s
;
key_
=
new
(
tc
)
byte
[
sz_
];
key_
=
new
byte
[
sz_
];
}
...
...
@@ -199,7 +199,7 @@ void PublicKey::SetKey(const byte* k)
void
PublicKey
::
AddToEnd
(
const
byte
*
data
,
word32
len
)
{
mySTL
::
auto_ptr
<
byte
>
tmp
(
new
(
tc
)
byte
[
sz_
+
len
]);
mySTL
::
auto_ptr
<
byte
>
tmp
(
new
byte
[
sz_
+
len
]);
memcpy
(
tmp
.
get
(),
key_
,
sz_
);
memcpy
(
tmp
.
get
()
+
sz_
,
data
,
len
);
...
...
@@ -218,7 +218,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h)
{
if
(
n
)
{
int
sz
=
strlen
(
n
);
name_
=
new
(
tc
)
char
[
sz
+
1
];
name_
=
new
char
[
sz
+
1
];
memcpy
(
name_
,
n
,
sz
);
name_
[
sz
]
=
0
;
}
...
...
@@ -480,7 +480,7 @@ void CertDecoder::Decode(SignerList* signers)
}
else
if
(
!
ValidateSignature
(
signers
))
source_
.
SetError
(
SIG_
CONFIRM
_E
);
source_
.
SetError
(
SIG_
OTHER
_E
);
}
...
...
@@ -632,7 +632,7 @@ word32 CertDecoder::GetSignature()
}
sigLength_
--
;
signature_
=
new
(
tc
)
byte
[
sigLength_
];
signature_
=
new
byte
[
sigLength_
];
memcpy
(
signature_
,
source_
.
get_current
(),
sigLength_
);
source_
.
advance
(
sigLength_
);
...
...
@@ -653,7 +653,7 @@ word32 CertDecoder::GetDigest()
sigLength_
=
GetLength
(
source_
);
signature_
=
new
(
tc
)
byte
[
sigLength_
];
signature_
=
new
byte
[
sigLength_
];
memcpy
(
signature_
,
source_
.
get_current
(),
sigLength_
);
source_
.
advance
(
sigLength_
);
...
...
@@ -693,7 +693,7 @@ void CertDecoder::GetName(NameType nt)
if
(
id
==
COMMON_NAME
)
{
char
*&
ptr
=
(
nt
==
ISSUER
)
?
issuer_
:
subject_
;
ptr
=
new
(
tc
)
char
[
strLen
+
1
];
ptr
=
new
char
[
strLen
+
1
];
memcpy
(
ptr
,
source_
.
get_current
(),
strLen
);
ptr
[
strLen
]
=
0
;
}
...
...
@@ -810,15 +810,15 @@ bool CertDecoder::ConfirmSignature(Source& pub)
mySTL
::
auto_ptr
<
HASH
>
hasher
;
if
(
signatureOID_
==
MD5wRSA
)
{
hasher
.
reset
(
new
(
tc
)
MD5
);
hasher
.
reset
(
new
MD5
);
ht
=
MD5h
;
}
else
if
(
signatureOID_
==
MD2wRSA
)
{
hasher
.
reset
(
new
(
tc
)
MD2
);
hasher
.
reset
(
new
MD2
);
ht
=
MD2h
;
}
else
if
(
signatureOID_
==
SHAwRSA
||
signatureOID_
==
SHAwDSA
)
{
hasher
.
reset
(
new
(
tc
)
SHA
);
hasher
.
reset
(
new
SHA
);
ht
=
SHAh
;
}
else
{
...
...
extra/yassl/taocrypt/src/dh.cpp
View file @
424e4ee1
...
...
@@ -26,7 +26,6 @@
#include "runtime.hpp"
#include "dh.hpp"
#include "asn.hpp"
#include <math.h>
namespace
TaoCrypt
{
...
...
extra/yassl/taocrypt/src/dsa.cpp
View file @
424e4ee1
...
...
@@ -27,8 +27,6 @@
#include "modarith.hpp"
#include "stdexcept.hpp"
#include "algebra.cpp" // for GCC 3.2 on aix ?
namespace
TaoCrypt
{
...
...
extra/yassl/taocrypt/src/integer.cpp
View file @
424e4ee1
...
...
@@ -38,11 +38,10 @@
#include "asn.hpp"
#include "stdexcept.hpp"
#include "algebra.cpp"
#ifdef __DECCXX
#include <c_asm.h> // for asm
multiply overflow
#include <c_asm.h> // for asm
overflow assembly
#endif
...
...
@@ -63,7 +62,7 @@
#pragma message("You do not seem to have the Visual C++ Processor Pack ")
#pragma message("installed, so use of SSE2 intrinsics will be disabled.")
#elif defined(__GNUC__) && defined(__i386__)
/* #warning You do not have GCC 3.3 or later, or did not specify the -msse2 \
/*
#warning You do not have GCC 3.3 or later, or did not specify the -msse2 \
compiler option. Use of SSE2 intrinsics will be disabled.
*/
#endif
...
...
@@ -109,7 +108,7 @@ CPP_TYPENAME AllocatorBase<T>::pointer AlignedAllocator<T>::allocate(
assert
(
IsAlignedOn
(
p
,
16
));
return
(
T
*
)
p
;
}
return
new
(
tc
)
T
[
n
];
return
new
T
[
n
];
}
...
...
@@ -178,7 +177,7 @@ DWord() {}
#elif defined(__DECCXX)
r
.
halfs_
.
high
=
asm
(
"umulh %a0, %a1, %v0"
,
a
,
b
);
#else
#error
unsupported alpha compiler for asm
multiply overflow
#error
can not implement
multiply overflow
#endif
#elif defined(__ia64__)
r
.
halfs_
.
low
=
a
*
b
;
...
...
@@ -392,6 +391,7 @@ S DivideThreeWordsByTwo(S* A, S B0, S B1, D* dummy_VC6_WorkAround = 0)
return
Q
;
}
// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1
template
<
class
S
,
class
D
>
inline
D
DivideFourWordsByTwo
(
S
*
T
,
const
D
&
Al
,
const
D
&
Ah
,
const
D
&
B
)
...
...
@@ -470,66 +470,6 @@ static inline unsigned int RoundupSize(unsigned int n)
}
template
<
class
T
>
static
Integer
StringToInteger
(
const
T
*
str
)
{
word
radix
;
unsigned
int
length
;
for
(
length
=
0
;
str
[
length
]
!=
0
;
length
++
)
{}
Integer
v
;
if
(
length
==
0
)
return
v
;
switch
(
str
[
length
-
1
])
{
case
'h'
:
case
'H'
:
radix
=
16
;
break
;
case
'o'
:
case
'O'
:
radix
=
8
;
break
;
case
'b'
:
case
'B'
:
radix
=
2
;
break
;
default:
radix
=
10
;
}
if
(
length
>
2
&&
str
[
0
]
==
'0'
&&
str
[
1
]
==
'x'
)
radix
=
16
;
for
(
unsigned
i
=
0
;
i
<
length
;
i
++
)
{
word
digit
;
if
(
str
[
i
]
>=
'0'
&&
str
[
i
]
<=
'9'
)
digit
=
str
[
i
]
-
'0'
;
else
if
(
str
[
i
]
>=
'A'
&&
str
[
i
]
<=
'F'
)
digit
=
str
[
i
]
-
'A'
+
10
;
else
if
(
str
[
i
]
>=
'a'
&&
str
[
i
]
<=
'f'
)
digit
=
str
[
i
]
-
'a'
+
10
;
else
digit
=
radix
;
if
(
digit
<
radix
)
{
v
*=
radix
;
v
+=
digit
;
}
}
if
(
str
[
0
]
==
'-'
)
v
.
Negate
();
return
v
;
}
static
int
Compare
(
const
word
*
A
,
const
word
*
B
,
unsigned
int
N
)
{
while
(
N
--
)
...
...
@@ -2308,85 +2248,6 @@ void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B,
}
}
/*
template <class P>
void RecursiveMultiplyTop(word *R, word *T, const word *L, const word *A,
const word *B, unsigned int N, const P *dummy=0)
{
assert(N>=2 && N%2==0);
if (N==4)
{
P::Multiply4(T, A, B);
((dword *)R)[0] = ((dword *)T)[2];
((dword *)R)[1] = ((dword *)T)[3];
}
else if (N==2)
{
P::Multiply2(T, A, B);
((dword *)R)[0] = ((dword *)T)[1];
}
else
{
const unsigned int N2 = N/2;
int carry;
int aComp = Compare(A0, A1, N2);
int bComp = Compare(B0, B1, N2);
switch (2*aComp + aComp + bComp)
{
case -4:
P::Subtract(R0, A1, A0, N2);
P::Subtract(R1, B0, B1, N2);
RecursiveMultiply<P>(T0, T2, R0, R1, N2);
P::Subtract(T1, T1, R0, N2);
carry = -1;
break;
case -2:
P::Subtract(R0, A1, A0, N2);
P::Subtract(R1, B0, B1, N2);
RecursiveMultiply<P>(T0, T2, R0, R1, N2);
carry = 0;
break;
case 2:
P::Subtract(R0, A0, A1, N2);
P::Subtract(R1, B1, B0, N2);
RecursiveMultiply<P>(T0, T2, R0, R1, N2);
carry = 0;
break;
case 4:
P::Subtract(R0, A1, A0, N2);
P::Subtract(R1, B0, B1, N2);
RecursiveMultiply<P>(T0, T2, R0, R1, N2);
P::Subtract(T1, T1, R1, N2);
carry = -1;
break;
default:
SetWords(T0, 0, N);
carry = 0;
}
RecursiveMultiply<P>(T2, R0, A1, B1, N2);
// now T[01] holds (A1-A0)*(B0-B1), T[23] holds A1*B1
word c2 = P::Subtract(R0, L+N2, L, N2);
c2 += P::Subtract(R0, R0, T0, N2);
word t = (Compare(R0, T2, N2) == -1);
carry += t;
carry += Increment(R0, N2, c2+t);
carry += P::Add(R0, R0, T1, N2);
carry += P::Add(R0, R0, T3, N2);
assert (carry >= 0 && carry <= 2);
CopyWords(R1, T3, N2);
Increment(R1, N2, carry);
}
}
*/
void
RecursiveMultiplyTop
(
word
*
R
,
word
*
T
,
const
word
*
L
,
const
word
*
A
,
const
word
*
B
,
unsigned
int
N
)
...
...
@@ -2739,20 +2600,6 @@ Integer::Integer(word value, unsigned int length)
}
Integer
::
Integer
(
const
char
*
str
)
:
reg_
(
2
),
sign_
(
POSITIVE
)
{
*
this
=
StringToInteger
(
str
);
}
Integer
::
Integer
(
const
wchar_t
*
str
)
:
reg_
(
2
),
sign_
(
POSITIVE
)
{
*
this
=
StringToInteger
(
str
);
}
Integer
::
Integer
(
const
byte
*
encodedInteger
,
unsigned
int
byteCount
,
Signedness
s
)
{
...
...
@@ -3358,76 +3205,6 @@ Integer Integer::Times(const Integer &b) const
#undef R2
#undef R3
/*
// do a 3 word by 2 word divide, returns quotient and leaves remainder in A
static word SubatomicDivide(word *A, word B0, word B1)
{
// assert {A[2],A[1]} < {B1,B0}, so quotient can fit in a word
assert(A[2] < B1 || (A[2]==B1 && A[1] < B0));
dword p, u;
word Q;
// estimate the quotient: do a 2 word by 1 word divide
if (B1+1 == 0)
Q = A[2];
else
Q = word(MAKE_DWORD(A[1], A[2]) / (B1+1));
// now subtract Q*B from A
p = (dword) B0*Q;
u = (dword) A[0] - LOW_WORD(p);
A[0] = LOW_WORD(u);
u = (dword) A[1] - HIGH_WORD(p) - (word)(0-HIGH_WORD(u)) - (dword)B1*Q;
A[1] = LOW_WORD(u);
A[2] += HIGH_WORD(u);
// Q <= actual quotient, so fix it
while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0))
{
u = (dword) A[0] - B0;
A[0] = LOW_WORD(u);
u = (dword) A[1] - B1 - (word)(0-HIGH_WORD(u));
A[1] = LOW_WORD(u);
A[2] += HIGH_WORD(u);
Q++;
assert(Q); // shouldn't overflow
}
return Q;
}
*/
/*
// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1
static inline void AtomicDivide(word *Q, const word *A, const word *B)
{
if (!B[0] && !B[1]) // if divisor is 0, we assume divisor==2**(2*WORD_BITS)
{
Q[0] = A[2];
Q[1] = A[3];
}
else
{
word T[4];
T[0] = A[0]; T[1] = A[1]; T[2] = A[2]; T[3] = A[3];
Q[1] = SubatomicDivide(T+1, B[0], B[1]);
Q[0] = SubatomicDivide(T, B[0], B[1]);
#ifndef NDEBUG
// multiply quotient and divisor and add remainder
// make sure it equals dividend
assert(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
word P[4];
LowLevel::Multiply2(P, Q, B);
Add(P, P, T, 4);
assert(memcmp(P, A, 4*WORD_SIZE)==0);
#endif
}
}
*/
static
inline
void
AtomicDivide
(
word
*
Q
,
const
word
*
A
,
const
word
*
B
)
{
...
...
@@ -3772,7 +3549,7 @@ Integer a_exp_b_mod_c(const Integer &x, const Integer& e, const Integer& m)
Integer
Integer
::
Gcd
(
const
Integer
&
a
,
const
Integer
&
b
)
{
return
EuclideanDomainOf
<
Integer
>
().
Gcd
(
a
,
b
);
return
EuclideanDomainOf
().
Gcd
(
a
,
b
);
}
Integer
Integer
::
InverseMod
(
const
Integer
&
m
)
const
...
...
@@ -3955,7 +3732,7 @@ Integer ModularArithmetic::CascadeExponentiate(const Integer &x,
dr
.
ConvertIn
(
y
),
e2
));
}
else
return
AbstractRing
<
Integer
>
::
CascadeExponentiate
(
x
,
e1
,
y
,
e2
);
return
AbstractRing
::
CascadeExponentiate
(
x
,
e1
,
y
,
e2
);
}
void
ModularArithmetic
::
SimultaneousExponentiate
(
Integer
*
results
,
...
...
@@ -3971,7 +3748,7 @@ void ModularArithmetic::SimultaneousExponentiate(Integer *results,
results
[
i
]
=
dr
.
ConvertOut
(
results
[
i
]);
}
else
AbstractRing
<
Integer
>
::
SimultaneousExponentiate
(
results
,
base
,
AbstractRing
::
SimultaneousExponentiate
(
results
,
base
,
exponents
,
exponentsCount
);
}
...
...
@@ -4170,10 +3947,6 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq,
}
#ifdef __GNUC__
template
Integer
StringToInteger
<
char
>(
char
const
*
);
template
Integer
StringToInteger
<
wchar_t
>(
wchar_t
const
*
);
template
class
EuclideanDomainOf
<
Integer
>;
template
class
AbstractEuclideanDomain
<
Integer
>;
template
unsigned
int
DivideThreeWordsByTwo
<
unsigned
int
,
DWord
>(
unsigned
int
*
,
unsigned
int
,
unsigned
int
,
DWord
*
);
#endif
...
...
extra/yassl/taocrypt/src/misc.cpp
View file @
424e4ee1
...
...
@@ -27,36 +27,9 @@
#include <new> // for NewHandler
void
*
operator
new
(
size_t
sz
,
TaoCrypt
::
new_t
)
{
void
*
ptr
=
::
operator
new
(
sz
);
if
(
!
ptr
)
abort
();
return
ptr
;
}
void
*
operator
new
[](
size_t
sz
,
TaoCrypt
::
new_t
tc
)
{
#if defined(_MSC_VER) && (_MSC_VER < 1300)
void
*
ptr
=
::
operator
new
(
sz
);
// no ::operator new[]
#else
void
*
ptr
=
::
operator
new
[](
sz
);
#endif
if
(
!
ptr
)
abort
();
return
ptr
;
}
namespace
TaoCrypt
{
new_t
tc
;
// for library new
inline
void
XorWords
(
word
*
r
,
const
word
*
a
,
unsigned
int
n
)
{
for
(
unsigned
int
i
=
0
;
i
<
n
;
i
++
)
...
...
extra/yassl/taocrypt/src/random.cpp
View file @
424e4ee1
...
...
@@ -26,7 +26,6 @@
#include "runtime.hpp"
#include "random.hpp"
#include "stdexcept.hpp"
#if defined(WIN32)
#define _WIN32_WINNT 0x0400
...
...
extra/yassl/taocrypt/src/rsa.cpp
View file @
424e4ee1
...
...
@@ -27,7 +27,6 @@
#include "modarith.hpp"
#include "stdexcept.hpp"
#include "algebra.cpp" // for GCC 3.2 on aix ?
namespace
TaoCrypt
{
...
...
@@ -214,8 +213,6 @@ word32 SSL_Decrypt(const RSA_PublicKey& key, const byte* sig, byte* plain)
#ifdef __GNUC__
template
AllocatorWithCleanup
<
unsigned
char
>
::
pointer
StdReallocate
<
unsigned
char
,
AllocatorWithCleanup
<
unsigned
char
>
>
(
AllocatorWithCleanup
<
unsigned
char
>&
,
unsigned
char
*
,
AllocatorWithCleanup
<
unsigned
char
>::
size_type
,
AllocatorWithCleanup
<
unsigned
char
>::
size_type
,
bool
);
template
AllocatorWithCleanup
<
unsigned
int
>
::
pointer
StdReallocate
<
unsigned
int
,
AllocatorWithCleanup
<
unsigned
int
>
>
(
AllocatorWithCleanup
<
unsigned
int
>&
,
unsigned
int
*
,
AllocatorWithCleanup
<
unsigned
int
>::
size_type
,
AllocatorWithCleanup
<
unsigned
int
>::
size_type
,
bool
);
template
class
AbstractGroup
<
Integer
>;
template
class
AbstractRing
<
Integer
>;
template
class
RSA_Decryptor
<
RSA_BlockType2
>;
template
class
RSA_Encryptor
<
RSA_BlockType1
>;
template
class
RSA_Encryptor
<
RSA_BlockType2
>;
...
...
@@ -227,11 +224,7 @@ template class RSA_Encryptor<RSA_BlockType2>;
namespace
mySTL
{
template
TaoCrypt
::
Integer
*
uninit_copy
<
TaoCrypt
::
Integer
*
,
TaoCrypt
::
Integer
*
>(
TaoCrypt
::
Integer
*
,
TaoCrypt
::
Integer
*
,
TaoCrypt
::
Integer
*
);
template
TaoCrypt
::
Integer
*
uninit_fill_n
<
TaoCrypt
::
Integer
*
,
unsigned
int
,
TaoCrypt
::
Integer
>(
TaoCrypt
::
Integer
*
,
unsigned
int
,
TaoCrypt
::
Integer
const
&
);
template
TaoCrypt
::
WindowSlider
*
uninit_copy
<
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
>(
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
);
template
vector
<
TaoCrypt
::
Integer
>
*
uninit_fill_n
<
vector
<
TaoCrypt
::
Integer
>*
,
unsigned
int
,
vector
<
TaoCrypt
::
Integer
>
>
(
vector
<
TaoCrypt
::
Integer
>*
,
unsigned
int
,
vector
<
TaoCrypt
::
Integer
>
const
&
);
template
void
destroy
<
TaoCrypt
::
Integer
*
>(
TaoCrypt
::
Integer
*
,
TaoCrypt
::
Integer
*
);
template
void
destroy
<
TaoCrypt
::
WindowSlider
*
>(
TaoCrypt
::
WindowSlider
*
,
TaoCrypt
::
WindowSlider
*
);
template
void
destroy
<
vector
<
TaoCrypt
::
Integer
>
*>
(
vector
<
TaoCrypt
::
Integer
>*
,
vector
<
TaoCrypt
::
Integer
>*
);
}
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment