~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to integer.h

  • Committer: noloader
  • Date: 2015-07-16 04:38:08 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:590
Added targets for UBsan and Asan

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include <iosfwd>
10
10
#include <algorithm>
11
11
 
12
 
#ifdef CRYPTOPP_X86ASM_AVAILABLE
13
 
 
14
 
#ifdef _M_IX86
15
 
        #if (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 500)) || (defined(__ICL) && (__ICL >= 500))
16
 
                #define SSE2_INTRINSICS_AVAILABLE
17
 
                #define CRYPTOPP_MM_MALLOC_AVAILABLE
18
 
        #elif defined(_MSC_VER)
19
 
                // _mm_free seems to be the only way to tell if the Processor Pack is installed or not
20
 
                #include <malloc.h>
21
 
                #if defined(_mm_free)
22
 
                        #define SSE2_INTRINSICS_AVAILABLE
23
 
                        #define CRYPTOPP_MM_MALLOC_AVAILABLE
24
 
                #endif
25
 
        #endif
26
 
#endif
27
 
 
28
 
// SSE2 intrinsics work in GCC 3.3 or later
29
 
#if defined(__SSE2__) && (__GNUC__ > 3 || __GNUC_MINOR__ > 2)
30
 
        #define SSE2_INTRINSICS_AVAILABLE
31
 
#endif
32
 
 
33
 
#endif
34
 
 
35
12
NAMESPACE_BEGIN(CryptoPP)
36
13
 
37
 
#if defined(SSE2_INTRINSICS_AVAILABLE)
38
 
        template <class T>
39
 
        class AlignedAllocator : public AllocatorBase<T>
40
 
        {
41
 
        public:
42
 
                CRYPTOPP_INHERIT_ALLOCATOR_TYPES
43
 
 
44
 
                pointer allocate(size_type n, const void *);
45
 
                void deallocate(void *p, size_type n);
46
 
                pointer reallocate(T *p, size_type oldSize, size_type newSize, bool preserve)
47
 
                {
48
 
                        return StandardReallocate(*this, p, oldSize, newSize, preserve);
49
 
                }
50
 
 
51
 
        #if !(defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16) || defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE))
52
 
        #define CRYPTOPP_NO_ALIGNED_ALLOC
53
 
                AlignedAllocator() : m_pBlock(NULL) {}
54
 
        protected:
55
 
                void *m_pBlock;
56
 
        #endif
57
 
        };
58
 
 
59
 
        #ifdef CRYPTOPP_IMPORTS
60
 
                CRYPTOPP_DLL_TEMPLATE_CLASS AlignedAllocator<word>;
61
 
        #endif
62
 
 
63
 
        typedef SecBlock<word, AlignedAllocator<word> > SecAlignedWordBlock;
64
 
#else
65
 
        typedef SecWordBlock SecAlignedWordBlock;
66
 
#endif
67
 
 
68
 
void CRYPTOPP_DLL CRYPTOPP_API DisableSSE2();
69
 
 
70
14
struct InitializeInteger        // used to initialize static variables
71
15
{
72
16
        InitializeInteger();
73
17
};
74
18
 
 
19
typedef SecBlock<word, AllocatorWithCleanup<word, CRYPTOPP_BOOL_X86> > IntegerSecBlock;
 
20
 
75
21
//! multiple precision integer and basic arithmetics
76
22
/*! This class can represent positive and negative integers
77
23
        with absolute value less than (256**sizeof(word)) ** (256**sizeof(int)).
429
375
        friend void PositiveMultiply(Integer &product, const Integer &a, const Integer &b);
430
376
        friend void PositiveDivide(Integer &remainder, Integer &quotient, const Integer &dividend, const Integer &divisor);
431
377
 
432
 
        SecAlignedWordBlock reg;
 
378
        IntegerSecBlock reg;
433
379
        Sign sign;
434
380
};
435
381
 
462
408
 
463
409
NAMESPACE_END
464
410
 
 
411
#ifndef __BORLANDC__
465
412
NAMESPACE_BEGIN(std)
466
 
template<> inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
 
413
inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
467
414
{
468
415
        a.swap(b);
469
416
}
470
417
NAMESPACE_END
 
418
#endif
471
419
 
472
420
#endif