Skip to content

Commit ee55c4e

Browse files
authored
minor cleanup and formatting changes
1 parent 695c3b2 commit ee55c4e

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

demos/demo_dynamic.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
print
5959
print(' demo_dynamic.py')
6060

61-
#---------------------------------------------------------------
61+
62+
#-------------------------------------------------------------------------------
6263
# load the .dylib
6364

6465
libname = 'tomcrypt'
@@ -71,8 +72,7 @@
7172
print
7273

7374

74-
75-
#---------------------------------------------------------------
75+
#-------------------------------------------------------------------------------
7676
# get list of all supported constants followed by a list of all
7777
# supported sizes. One alternative: these lists may be parsed
7878
# and used as needed.
@@ -84,7 +84,7 @@
8484
# get size to allocate for constants output list
8585
str_len = c_int(0)
8686
ret = LTC.crypt_list_all_constants(None, byref(str_len))
87-
print ' need to allocate %d bytes \n' % str_len.value
87+
print ' need to allocate %d bytes to build list \n' % str_len.value
8888

8989
# allocate that size and get (name, size) pairs, each pair
9090
# separated by a newline char.
@@ -101,7 +101,7 @@
101101
# get size to allocate for sizes output list
102102
str_len = c_int(0)
103103
ret = LTC.crypt_list_all_sizes(None, byref(str_len))
104-
print ' need to allocate %d bytes \n' % str_len.value
104+
print ' need to allocate %d bytes to build list \n' % str_len.value
105105

106106
# allocate that size and get (name, size) pairs, each pair
107107
# separated by a newline char.
@@ -111,7 +111,7 @@
111111
print
112112

113113

114-
#---------------------------------------------------------------
114+
#-------------------------------------------------------------------------------
115115
# get individually named constants and sizes
116116

117117
# print selected constants
@@ -131,6 +131,7 @@
131131
rc = LTC.crypt_get_constant(name, byref(const_value))
132132
value = const_value.value
133133
print ' %-25s %d' % (name, value)
134+
print
134135

135136
# print selected sizes
136137
if SHOW_SELECTED_SIZES:
@@ -151,10 +152,11 @@
151152
rc = LTC.crypt_get_size(name, byref(size_value))
152153
value = size_value.value
153154
print ' %-25s %d' % (name, value)
155+
print
154156

155157

156-
#---------------------------------------------------------------
157-
#---------------------------------------------------------------
158+
#-------------------------------------------------------------------------------
159+
#-------------------------------------------------------------------------------
158160
# LibTomCrypt exposes one interesting string that can be accessed
159161
# via Python's ctypes module, "crypt_build_settings", which
160162
# provides a list of this build's compiler switches and supported
@@ -170,12 +172,10 @@ def get_named_string(lib, name):
170172
print 'This is a string compiled into LTC showing compile '
171173
print 'options and algorithms supported by this build \n'
172174
print get_named_string(LTC, 'crypt_build_settings')
173-
print
174-
175175

176176

177-
#---------------------------------------------------------------
178-
#---------------------------------------------------------------
177+
#-------------------------------------------------------------------------------
178+
#-------------------------------------------------------------------------------
179179
# here is an example of how Python code can be written to access
180180
# LTC's implementation of SHA256 and ChaCha,
181181

@@ -235,7 +235,7 @@ def crypt(self, datain):
235235
return dataout.raw
236236

237237
# - - - - - - - - - - - - -
238-
# a SHA256 app fragment...
238+
# a SHA256 app fragment
239239

240240
# from wrapper import * # uncomment in real life
241241

@@ -251,7 +251,7 @@ def crypt(self, datain):
251251
print template % (data, md.encode('hex'))
252252

253253
# - - - - - - - - - - - - -
254-
# a ChaCha app fragment...
254+
# a ChaCha app fragment
255255

256256
if SHOW_CHACHA_EXAMPLE:
257257
print '-'*60
@@ -274,8 +274,10 @@ def crypt(self, datain):
274274
template = ' ChaCha%d decoded text for "%s" is "%s" \n'
275275
print template % (rounds, plain, decrypted)
276276

277+
# Footnote: Keys should be erased fm memory as soon as possible after use,
278+
# and that includes Python. For a tip on how to do that in Python, see
279+
# http://buggywhip.blogspot.com/2010/12/erase-keys-and-credit-card-numbers-in.html
277280

278-
279-
#---------------------------------------------------------------
280-
#---------------------------------------------------------------
281-
#---------------------------------------------------------------
281+
#-------------------------------------------------------------------------------
282+
#-------------------------------------------------------------------------------
283+
#-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)