BVB Source Codes

DeDRM_tools Show openssl_des.py Source code

Return Download DeDRM_tools: download openssl_des.py Source code - Download DeDRM_tools Source code - Type:.py
  1. #!/usr/bin/env python
  2. # vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
  3.  
  4. # implement just enough of des from openssl to make erdr2pml.py happy
  5.  
  6. def load_libcrypto():
  7.     from ctypes import CDLL, POINTER, c_void_p, c_char_p, c_char, c_int, c_long, \
  8.         Structure, c_ulong, create_string_buffer, cast
  9.     from ctypes.util import find_library
  10.     import sys
  11.  
  12.     if sys.platform.startswith('win'):
  13.         libcrypto = find_library('libeay32')
  14.     else:
  15.         libcrypto = find_library('crypto')
  16.  
  17.     if libcrypto is None:
  18.         return None
  19.  
  20.     libcrypto = CDLL(libcrypto)
  21.  
  22.     # typedef struct DES_ks
  23.     #     {
  24.     #     union
  25.     #         {
  26.     #         DES_cblock cblock;
  27.     #         /* make sure things are correct size on machines with
  28.     #          * 8 byte longs */
  29.     #         DES_LONG deslong[2];
  30.     #         } ks[16];
  31.     #     } DES_key_schedule;
  32.  
  33.     # just create a big enough place to hold everything
  34.     # it will have alignment of structure so we should be okay (16 byte aligned?)
  35.     class DES_KEY_SCHEDULE(Structure):
  36.         _fields_ = [('DES_cblock1', c_char * 16),
  37.                     ('DES_cblock2', c_char * 16),
  38.                     ('DES_cblock3', c_char * 16),
  39.                     ('DES_cblock4', c_char * 16),
  40.                     ('DES_cblock5', c_char * 16),
  41.                     ('DES_cblock6', c_char * 16),
  42.                     ('DES_cblock7', c_char * 16),
  43.                     ('DES_cblock8', c_char * 16),
  44.                     ('DES_cblock9', c_char * 16),
  45.                     ('DES_cblock10', c_char * 16),
  46.                     ('DES_cblock11', c_char * 16),
  47.                     ('DES_cblock12', c_char * 16),
  48.                     ('DES_cblock13', c_char * 16),
  49.                     ('DES_cblock14', c_char * 16),
  50.                     ('DES_cblock15', c_char * 16),
  51.                     ('DES_cblock16', c_char * 16)]
  52.  
  53.     DES_KEY_SCHEDULE_p = POINTER(DES_KEY_SCHEDULE)
  54.  
  55.     def F(restype, name, argtypes):
  56.         func = getattr(libcrypto, name)
  57.         func.restype = restype
  58.         func.argtypes = argtypes
  59.         return func
  60.  
  61.     DES_set_key = F(None, 'DES_set_key',[c_char_p, DES_KEY_SCHEDULE_p])
  62.     DES_ecb_encrypt = F(None, 'DES_ecb_encrypt',[c_char_p, c_char_p, DES_KEY_SCHEDULE_p, c_int])
  63.  
  64.  
  65.     class DES(object):
  66.         def __init__(self, key):
  67.             if len(key) != 8 :
  68.                 raise Exception('DES improper key used')
  69.                 return
  70.             self.key = key
  71.             self.keyschedule = DES_KEY_SCHEDULE()
  72.             DES_set_key(self.key, self.keyschedule)
  73.         def desdecrypt(self, data):
  74.             ob = create_string_buffer(len(data))
  75.             DES_ecb_encrypt(data, ob, self.keyschedule, 0)
  76.             return ob.raw
  77.         def decrypt(self, data):
  78.             if not data:
  79.                 return ''
  80.             i = 0
  81.             result = []
  82.             while i < len(data):
  83.                 block = data[i:i+8]
  84.                 processed_block = self.desdecrypt(block)
  85.                 result.append(processed_block)
  86.                 i += 8
  87.             return ''.join(result)
  88.  
  89.     return DES
  90.  
downloadopenssl_des.py Source code - Download DeDRM_tools Source code
Related Source Codes/Software:
kcp - KCP - A Fast and Reliable ARQ Protocol 2017-04-08
cloc - cloc counts blank lines, comment lines, and physic... 2017-04-08
nvidia-docker - Build and run Docker containers leveraging NVIDIA ... 2017-04-08
quickstart - Angular 2 QuickStart - source from the documentati... 2017-04-08
jQuery-Autocomplete - Ajax Autocomplete for jQuery allows you to easily ... 2017-04-08
fuckitjs - The Original Javascript Error Steamroller 2017-04-09
eslint-plugin-react - React specific linting rules for ESLint 2017-04-09
husky - 2017-04-09
electron-builder - A complete solution to package and build a ready f... 2017-04-09
jsfeat - JavaScript Computer Vision library. 2017-04-16
flakes - Flakes is an Admin Template Framework. A combinati... 2017-04-15
capstone - Capstone disassembly/disassembler framework: Core ... 2017-04-15
nginx-resources - A collection of resources covering Nginx, Nginx + ... 2017-04-15
utron - A lightweight MVC framework for Go(Golang) 2017-04-15
cfssl - CFSSL: Cloudflare's PKI and TLS toolkit ... 2017-04-15
HandBrake - HandBrake's main development repository ... 2017-04-15
Awesome-Networking - A curated list of awesome networking libraries, re... 2017-04-15
react-sortable-hoc - A set of higher-order components to turn any list ... 2017-04-15
jugglingdb - Multi-database ORM for nodejs: redis, mongodb, mys... 2017-04-15

 Back to top