Home | History | Annotate | Download | only in src
      1 /*############################################################################
      2   # Copyright 2016-2017 Intel Corporation
      3   #
      4   # Licensed under the Apache License, Version 2.0 (the "License");
      5   # you may not use this file except in compliance with the License.
      6   # You may obtain a copy of the License at
      7   #
      8   #     http://www.apache.org/licenses/LICENSE-2.0
      9   #
     10   # Unless required by applicable law or agreed to in writing, software
     11   # distributed under the License is distributed on an "AS IS" BASIS,
     12   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13   # See the License for the specific language governing permissions and
     14   # limitations under the License.
     15   ############################################################################*/
     16 
     17 /*!
     18  * \file
     19  * \brief Big number private interface.
     20  */
     21 
     22 #ifndef EPID_COMMON_MATH_SRC_BIGNUM_INTERNAL_H_
     23 #define EPID_COMMON_MATH_SRC_BIGNUM_INTERNAL_H_
     24 
     25 #include "epid/common/errors.h"
     26 #include "epid/common/stdtypes.h"
     27 #include "epid/common/types.h"
     28 #include "ext/ipp/include/ippcp.h"
     29 
     30 typedef void* BNU;
     31 typedef void const* ConstBNU;
     32 typedef Ipp32u* IppBNU;
     33 typedef Ipp32u const* ConstIppBNU;
     34 typedef Ipp8u* IppOctStr;
     35 typedef Ipp8u const* ConstIppOctStr;
     36 
     37 /// Big Number
     38 struct BigNum {
     39   /// Internal implementation of bignum
     40   IppsBigNumState* ipp_bn;
     41 };
     42 
     43 /// convert octet string into "big number unsigned" representation
     44 /*!
     45 
     46 This is an internal function, used to convert an octet string (uint8_t
     47 array) into a big number unsigned representation (uint32_t array).
     48 For example, octet string {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
     49 0x08} is converted to {0x05060708, 0x01020304}
     50 
     51 \param[out] bnu_ptr
     52 Output big number unsigned array
     53 \param[in] octstr_ptr
     54 Input octal string
     55 \param[in] octstr_len
     56 Length of octet string, should be multiple of 4
     57 
     58 \returns length of big number unsigned in uint32_t chunks
     59 \returns -1 in case of any error
     60 */
     61 int OctStr2Bnu(BNU bnu_ptr, ConstOctStr octstr_ptr, int octstr_len);
     62 
     63 /// Get octet string size in bits
     64 /*!
     65 \param[in] octstr_ptr
     66 Input octet string.
     67 \param[in] octstr_len
     68 Length of octet string in bytes.
     69 
     70 \returns bit size of big number value from octet string
     71 */
     72 size_t OctStrBitSize(ConstOctStr octstr_ptr, size_t octstr_len);
     73 
     74 #endif  // EPID_COMMON_MATH_SRC_BIGNUM_INTERNAL_H_
     75