示例#1
0
            // finalize and compute the final digest
            //-------------------------------------------------
            //  finish - compute final hash
            //-------------------------------------------------
            public sha1_t finish()
            {
                unsigned padlen = 64U - (63U & (((unsigned)m_cnt >> 3) + 8U));
                MemoryU8 padbuf = new MemoryU8(64, true);  //uint8_t padbuf[64];

                padbuf[0] = 0x80;
                for (unsigned i = 1U; i < padlen; i++)
                {
                    padbuf[i] = 0x00;
                }
                MemoryU8 lenbuf = new MemoryU8(8, true);  //uint8_t lenbuf[8];

                for (unsigned i = 0U; i < 8U; i++)
                {
                    lenbuf[i] = (uint8_t)(m_cnt >> (int)((7U - i) << 3));
                }
                append(new PointerU8(padbuf), padlen);
                append(new PointerU8(lenbuf), (uint32_t)lenbuf.Count);
                sha1_t result = new sha1_t();

                for (unsigned i = 0U; i < 20U; i++)
                {
                    result.m_raw[i] = (uint8_t)(m_st[4U - (i >> 2)] >> (int)((3U - (i & 3)) << 3));
                }
                return(result);
            }
示例#2
0
            }                                                                                                                                //void compute(const uint8_t *data, uint32_t length, const char *types = nullptr) { begin(types); buffer(data, length); end(); }

            // internal helpers
            //-------------------------------------------------
            //  copyfrom - copy everything from another
            //  collection
            //-------------------------------------------------
            void copyfrom(hash_collection src)
            {
                // copy flags directly
                m_flags = src.m_flags;

                // copy hashes
                m_has_crc32 = src.m_has_crc32;
                m_crc32     = src.m_crc32;
                m_has_sha1  = src.m_has_sha1;
                m_sha1      = src.m_sha1;

                // don't copy creators
                m_creator = null;
            }
示例#3
0
            //-------------------------------------------------
            //  end - stop hashing
            //-------------------------------------------------
            void end()
            {
                //assert(m_creator != NULL);

                // finish up the CRC32
                if (m_creator.m_doing_crc32)
                {
                    m_has_crc32 = true;
                    m_crc32     = m_creator.m_crc32_creator.finish();
                }

                // finish up the SHA1
                if (m_creator.m_doing_sha1)
                {
                    m_has_sha1 = true;
                    m_sha1     = m_creator.m_sha1_creator.finish();
                }

                // nuke the creator
                //delete m_creator;
                m_creator = null;
            }
示例#4
0
 // SHA1-specific helpers
 //bool sha1(sha1_t &result) const { result = m_sha1; return m_has_sha1; }
 public void add_sha1(sha1_t sha1)
 {
     m_has_sha1 = true; m_sha1 = sha1;
 }