ucx/ucx.c

Thu, 05 Dec 2019 10:46:39 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 05 Dec 2019 10:46:39 +0100
changeset 691
48ec0ab17011
parent 505
481802342fdf
permissions
-rw-r--r--

fix encryption of files with specific length

5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * @mainpage UAP Common Extensions
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 * Library with common and useful functions, macros and data structures.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * <p>
335
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
5 * Latest available source:<br>
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
6 * <a href="https://sourceforge.net/projects/ucx/files/">
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
7 * https://sourceforge.net/projects/ucx/files/</a>
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
8 * </p>
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
9 *
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
10 * <p>
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
11 * Repositories:<br>
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
12 * <a href="https://sourceforge.net/p/ucx/code">
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
13 * https://sourceforge.net/p/ucx/code</a>
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
14 * -&nbsp;or&nbsp;-
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 * <a href="https://develop.uap-core.de/hg/ucx">
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * https://develop.uap-core.de/hg/ucx</a>
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * </p>
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * <h2>LICENCE</h2>
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 *
335
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
21 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * Redistribution and use in source and binary forms, with or without
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * modification, are permitted provided that the following conditions are met:
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * 1. Redistributions of source code must retain the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 * notice, this list of conditions and the following disclaimer.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 * 2. Redistributions in binary form must reproduce the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 * notice, this list of conditions and the following disclaimer in the
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 * documentation and/or other materials provided with the distribution.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 * POSSIBILITY OF SUCH DAMAGE.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 */
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
335
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
46 #include "ucx/ucx.h"
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
47
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
48 int ucx_szmul_impl(size_t a, size_t b, size_t *result) {
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
49 if(a == 0 || b == 0) {
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
50 *result = 0;
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
51 return 0;
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
52 }
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
53 size_t r = a * b;
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
54 if(r / b == a) {
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
55 *result = r;
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
56 return 0;
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
57 } else {
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
58 *result = 0;
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
59 return 1;
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
60 }
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
61 }
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
62

mercurial