public static unsafe void CalculateHMAC(int pg_offset, uint filesize, byte[] page_signatures, byte *result) { var b = CalculateHMAC(pg_offset, filesize, page_signatures); var buf = new ByteBufferRef(new IntPtr(result), (int)SHA1Managed.SHA1HashSize); buf.CopyFrom(0, b); }
private void SerializeMetadata(ByteBufferRef buf, int cursor) { Deserializer.WriteULong(HeaderMagic, buf, cursor); cursor += sizeof(ulong); var hmac = CalculateHMAC(DataPageOffset, FileSize, Signatures); buf.CopyFrom(cursor, hmac); cursor += HMACSize; Deserializer.WriteInt(DataPageOffset, buf, cursor); cursor += sizeof(int); Deserializer.WriteUInt(FileSize, buf, cursor); cursor += sizeof(uint); Deserializer.WriteInt(Signatures.Length, buf, cursor); cursor += sizeof(int); buf.CopyFrom(cursor, Signatures); }
private static int ReadUserBuffer(Thread current, ByteBufferRef src, int buf_offset, CachePage page, int page_offset, int len) { var dst = new ByteBufferRef(page.Buffer.Location + page_offset, len); dst.CopyFrom(buf_offset, src); return(0); }
private int PrepareBuffer(ByteBufferRef buf, CachePage[] sealed_page) { var cursor = 0; // Metadata for (var i = 0; i < DataPageOffset; ++i) { Deserializer.WriteInt(i, buf, cursor); cursor += sizeof(int); } for (var i = 0; i < sealed_page.Length; ++i) { var pgoffset = sealed_page[i].Location; Deserializer.WriteInt(pgoffset + DataPageOffset, buf, cursor); cursor += sizeof(int); if (pgoffset > MaximumPageOffset()) { Arch.Console.WriteLine("SecureFSINode::FlushAndCloseAsync, file too big"); Utils.Panic(); return(-1); } } var metadata_cursor = cursor; cursor += DataPageOffset * Arch.ArchDefinition.PageSize; // Copy data var sha1 = new SHA1Managed(); for (var i = 0; i < sealed_page.Length; ++i) { var page = sealed_page[i]; buf.CopyFrom(cursor, page.Buffer); sha1.Reset(); sha1.Input(page.Buffer); var r = sha1.GetResult(); for (var j = 0; j < r.Length; ++j) { Signatures[page.Location * HMACSize + j] = r[j]; } page.Dispose(); cursor += Arch.ArchDefinition.PageSize; } SerializeMetadata(buf, metadata_cursor); return(0); }