~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to filters/kocrypt/cbc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2001 George Staikos <staikos@kde.org>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License as published by the Free Software Foundation; either
7
 
   version 2 of the License, or (at your option) any later version.
8
 
 
9
 
   This library is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
   Library General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU Library General Public License
15
 
   along with this library; see the file COPYING.LIB.  If not, write to
16
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
   Boston, MA 02111-1307, USA.
18
 
*/
19
 
 
20
 
 
21
 
#include "cbc.h"
22
 
#include <string.h>
23
 
 
24
 
 
25
 
 
26
 
CipherBlockChain::CipherBlockChain(BlockCipher *cipher) : _cipher(cipher) {
27
 
   _next = NULL;
28
 
   _register = 0;
29
 
   _len = -1;
30
 
   _reader = _writer = 0;
31
 
   if (cipher)
32
 
     _blksz = cipher->blockSize();
33
 
}
34
 
 
35
 
 
36
 
CipherBlockChain::~CipherBlockChain() {
37
 
  if (_register) delete[] (char *)_register;
38
 
}
39
 
 
40
 
 
41
 
bool CipherBlockChain::setKey(void *key, int bitlength) {
42
 
if (_cipher) return _cipher->setKey(key, bitlength);
43
 
return false;
44
 
}
45
 
 
46
 
 
47
 
int CipherBlockChain::getKeyLen() {
48
 
if (_cipher) return _cipher->getKeyLen();
49
 
return -1;
50
 
}
51
 
 
52
 
 
53
 
bool CipherBlockChain::variableKeyLen() {
54
 
if (_cipher) return _cipher->variableKeyLen();
55
 
return false;
56
 
}
57
 
 
58
 
 
59
 
bool CipherBlockChain::readyToGo() {
60
 
if (_cipher) return _cipher->readyToGo();
61
 
return false;
62
 
}
63
 
 
64
 
 
65
 
int CipherBlockChain::encrypt(void *block, int len) {
66
 
if (_cipher && !_reader) {
67
 
  int rc;
68
 
 
69
 
  _writer |= 1;
70
 
 
71
 
  if (!_register) {
72
 
     _register = new unsigned char[len];
73
 
     _len = len;
74
 
     memset(_register, 0, len);
75
 
  } else if (len > _len) return -1;
76
 
 
77
 
  // This might be optimizable
78
 
  char *tb = (char *)block;
79
 
  for (int i = 0; i < len; i++) {
80
 
    tb[i] ^= ((char *)_register)[i];
81
 
  }
82
 
 
83
 
  rc = _cipher->encrypt(block, len);
84
 
 
85
 
  if (rc != -1) {
86
 
     memcpy(_register, block, len);
87
 
  }
88
 
 
89
 
  return rc;
90
 
}
91
 
return -1;
92
 
}
93
 
 
94
 
 
95
 
int CipherBlockChain::decrypt(void *block, int len) {
96
 
if (_cipher && !_writer) {
97
 
  int rc;
98
 
 
99
 
  _reader |= 1;
100
 
 
101
 
  if (!_register) {
102
 
     _register = new unsigned char[len];
103
 
     _len = len;
104
 
     memset(_register, 0, len);
105
 
  } else if (len > _len) {
106
 
     return -1;
107
 
  } 
108
 
 
109
 
  if (!_next)
110
 
     _next = new unsigned char[_len];
111
 
  memcpy(_next, block, _len);
112
 
 
113
 
  rc = _cipher->decrypt(block, len);
114
 
 
115
 
  if (rc != -1) {
116
 
    // This might be optimizable
117
 
    char *tb = (char *)block;
118
 
    for (int i = 0; i < len; i++) {
119
 
      tb[i] ^= ((char *)_register)[i];
120
 
    }
121
 
  }
122
 
 
123
 
  void *temp;
124
 
  temp = _next;
125
 
  _next = _register;
126
 
  _register = temp;
127
 
 
128
 
  return rc;
129
 
}
130
 
return -1;
131
 
}
132
 
 
133
 
 
134
 
 
135