Ejemplo n.º 1
0
      /**
       * Amends the user-provided search query with generic filter rules for
       * the associated system keychains.
       */
      scoped_CFType<CFDictionaryRef> prepareQuery(Query pairs) const
         {
         std::vector<CFStringRef> keys({kSecClass,
                                        kSecReturnRef,
                                        kSecMatchLimit,
                                        kSecMatchTrustedOnly,
                                        kSecMatchSearchList,
                                        kSecMatchPolicy});
         std::vector<CFTypeRef>   values({kSecClassCertificate,
                                          kCFBooleanTrue,
                                          kSecMatchLimitAll,
                                          kCFBooleanTrue,
                                          keychains(),
                                          policy()});
         keys.reserve(pairs.size() + keys.size());
         values.reserve(pairs.size() + values.size());

         for(const auto& pair : pairs)
            {
            keys.push_back(pair.first);
            values.push_back(pair.second);
            }

         BOTAN_ASSERT_EQUAL(keys.size(), values.size(), "valid key-value pairs");

         return scoped_CFType<CFDictionaryRef>(CFDictionaryCreate(
               kCFAllocatorDefault, (const void**)keys.data(),
               (const void**)values.data(), keys.size(),
               &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
         }
Ejemplo n.º 2
0
void Poly1305::add_data(const byte input[], size_t length)
   {
   BOTAN_ASSERT_EQUAL(m_poly.size(), 8, "Initialized");

   if(m_buf_pos)
      {
      buffer_insert(m_buf, m_buf_pos, input, length);

      if(m_buf_pos + length >= m_buf.size())
         {
         poly1305_blocks(m_poly, m_buf.data(), 1);
         input += (m_buf.size() - m_buf_pos);
         length -= (m_buf.size() - m_buf_pos);
         m_buf_pos = 0;
         }
      }

   const size_t full_blocks = length / m_buf.size();
   const size_t remaining   = length % m_buf.size();

   if(full_blocks)
      poly1305_blocks(m_poly, input, full_blocks);

   buffer_insert(m_buf, m_buf_pos, input + full_blocks * m_buf.size(), remaining);
   m_buf_pos += remaining;
   }
Ejemplo n.º 3
0
void* Compression_Alloc_Info::do_malloc(size_t n, size_t size)
   {
   const size_t total_size = n * size;

   BOTAN_ASSERT_EQUAL(total_size / size, n, "Overflow check");

   // TODO maximum length check here?

   void* ptr = std::malloc(total_size);

   /*
   * Return null rather than throwing here as we are being called by a
   * C library and it may not be possible for an exception to unwind
   * the call stack from here. The compression library is expecting a
   * function written in C and a null return on error, which it will
   * send upwards to the compression wrappers.
   */

   if(ptr)
      {
      std::memset(ptr, 0, total_size);
      m_current_allocs[ptr] = total_size;
      }

   return ptr;
   }
Ejemplo n.º 4
0
/*
* Pad with PKCS #7 Method
*/
void PKCS7_Padding::pad(byte block[], size_t size, size_t position) const
   {
   const size_t bytes_remaining = size - position;
   const byte pad_value = static_cast<byte>(bytes_remaining);

   BOTAN_ASSERT_EQUAL(pad_value, bytes_remaining,
                      "Overflow in PKCS7_Padding");

   for(size_t j = 0; j != size; ++j)
      block[j] = pad_value;
   }
Ejemplo n.º 5
0
/*
* Do heuristic tests for BER data
*/
bool maybe_BER(DataSource& source)
   {
   uint8_t first_u8;
   if(!source.peek_byte(first_u8))
      {
      BOTAN_ASSERT_EQUAL(source.read_byte(first_u8), 0, "Expected EOF");
      throw Stream_IO_Error("ASN1::maybe_BER: Source was empty");
      }

   if(first_u8 == (SEQUENCE | CONSTRUCTED))
      return true;
   return false;
   }
Ejemplo n.º 6
0
void PBKDF::pbkdf_iterations(byte out[], size_t out_len,
                             const std::string& passphrase,
                             const byte salt[], size_t salt_len,
                             size_t iterations) const
   {
   if(iterations == 0)
      throw std::invalid_argument(name() + ": Invalid iteration count");

   const size_t iterations_run = pbkdf(out, out_len, passphrase,
                                       salt, salt_len, iterations,
                                       std::chrono::milliseconds(0));
   BOTAN_ASSERT_EQUAL(iterations, iterations_run, "Expected PBKDF iterations");
   }
Ejemplo n.º 7
0
void Poly1305::final_result(byte out[])
   {
   BOTAN_ASSERT_EQUAL(m_poly.size(), 8, "Initialized");

   if(m_buf_pos != 0)
      {
      m_buf[m_buf_pos] = 1;
      const size_t len = m_buf.size() - m_buf_pos - 1;
      if (len > 0)
         {
         clear_mem(&m_buf[m_buf_pos+1], len);
         }
      poly1305_blocks(m_poly, m_buf.data(), 1, true);
      }

   poly1305_finish(m_poly, out);

   m_poly.clear();
   m_buf_pos = 0;
   }