Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Rar20Cipher.cpp « Rar20 « Crypto « 7zip « CPP - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27ccc493ab13afbc441b83bc59cb44bf7f21d180 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Crypto/Rar20Cipher.cpp

#include "StdAfx.h"

#include "Rar20Cipher.h"
#include "Windows/Defs.h"

namespace NCrypto {
namespace NRar20 {

static const int kBufferSize = 1 << 17;

STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
{
  _coder.SetPassword(data, size);
  return S_OK;
}

STDMETHODIMP CDecoder::Init()
{
  return S_OK;
}

STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
{
  const UInt16 kBlockSize = 16;
  if (size > 0 && size < kBlockSize)
    return kBlockSize;
  UInt32 i;
  for (i = 0; i + kBlockSize <= size; i += kBlockSize)
  {
    _coder.DecryptBlock(data + i);
  }
  return i;
}

/*
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
      ICompressProgressInfo *progress)
{
  UInt64 nowPos = 0;
  UInt32 bufferPos = 0;
  UInt32 processedSize;
  for (;;)
  {
    UInt32 size = kBufferSize - bufferPos;
    RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize));

    UInt32 anEndPos = bufferPos + processedSize;
    for (;bufferPos + 16 <= anEndPos; bufferPos += 16)
      _coder.DecryptBlock(_buffer + bufferPos);

    if (bufferPos == 0)
      return S_OK;

    if (outSize != NULL && nowPos + bufferPos > *outSize)
       bufferPos = UInt32(*outSize - nowPos);

    RINOK(outStream->Write(_buffer, bufferPos, &processedSize));
    if (bufferPos != processedSize)
      return E_FAIL;

    nowPos +=  processedSize;
    if (outSize != NULL && nowPos == *outSize)
      return S_OK;

    int i = 0;
    while(bufferPos < anEndPos)
      _buffer[i++] = _buffer[bufferPos++];
    bufferPos = i;
  }
}
*/

}}